大家好。我对 Extjs 完全陌生,我已经被插入到一个已经启动的大项目中并且独自一人。 当然,我正在研究框架,但我对每一个代码都感到震惊。
现在,我想了解在 POST 中使用 JSON 参数进行休息调用的正确方法。
这是我的实际情况:
我在 View 文件(称为 setup.js)中定义了一个组合框,并在选择上放置了一个监听器,如下所示
emptyText: 'Select a country',
listConfig: {
itemTpl: [
'<div><span class="" style="margin-right: 10px;"><img src="resources/flags/{id}.png"></span>{name}</div>'
]
},
listeners: {
/*created the after render listener to wait until the store is loaded. then I set the default value*/
select: 'onCountrySelect',
afterrender: 'onAfterRenderCombo'
}
在另一个名为 setupController.js 的文件中,我定义了所有函数:
onCountrySelect: function(a){
console.log("selected ",a.value);
var controller = this,
userData = controller.getUserData();
console.log("user.id",userData.id);
},
现在,在每个国家/地区选择操作中,我都必须将 JSON 发送到服务器,以“设置”用户使用的国家/地区。该调用还取决于环境,因为开发环境与生产环境不同,所以我想我必须制作某种代理,但也许这是稍后的问题,现在我想为此设置一个调用选择,因此我将在以后必须执行的所有调用中使用此逻辑。
问题是,有没有正确的方法来定义它?我需要模型吗?还是在商店里接听所有电话都很好?我是否需要...代理(?)或商店或“外部”的东西,以便我可以在其他地方使用相同的调用?有这方面的例子吗?
伙计们/女孩们,提前致谢。
最佳答案
就像这里写的那样 http://docs.sencha.com/extjs/6.0.2/classic/Ext.data.proxy.Ajax.html
代理可以与同一域中的服务器一起使用:
AjaxProxy cannot be used to retrieve data from other domains. If your application is running on http://domainA.com it cannot load data from http://domainB.com because browsers have a built-in security policy that prohibits domains talking to each other via AJAX.
就个人而言,我有一个与多个服务器连接的控制台,我使用像这样的ajax请求http://docs.sencha.com/extjs/6.0.2/modern/Ext.Ajax.html#method-request
Ext.Ajax.request({
url:'',
method:'POST',
params:{
json:YOURJSON
},
success:function(response){
},
failure:function(response){
}
});
我正在开发一个由ajax代理扩展的个人代理,可以在没有不同域问题的情况下进行ajax调用。如果您想做一个自制代理,您可以在这里阅读有关代理的所有内容:http://docs.sencha.com/extjs/6.0.2/classic/Ext.data.proxy.Proxy.html
或者您可以使用外部 JS 类来为您执行 ajax 请求。
关于javascript - Extjs 5.0.1 如何以正确的方式发送 JSON POST 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40258674/