Javascript ExtJS Ajax POST 与代理 POST
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11846057/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ExtJS Ajax POST vs Proxy POST
提问by Dragos
I am trying to create a grid panel using ExtJS 4.1. It gets its data from the server using an AJAX proxy:
我正在尝试使用 ExtJS 4.1 创建一个网格面板。它使用 AJAX 代理从服务器获取数据:
var store = Ext.create('Ext.data.Store', {
model: 'myModel',
pageSize: pageSize,
proxy: {
type: 'ajax',
url: "../search",
actionMethods: {
create: "POST",
read: "POST",
update: "POST",
destroy: "POST"
},
headers: {
'Content-Type': 'application/json'
},
limitParam: false,
startParam: false,
pageParam: false,
extraParams: JSON.stringify({
rows: pageSize,
role: "Admin",
index: myIndex,
question: searchPhrase
}),
reader: {
type: 'json',
root: 'results.results',
totalProperty: 'numFound',
model: 'myModel'
}
}
});
store.loadPage(1);
but it doesn't seem to work.
但它似乎不起作用。
I get an error message saying that the JSON could not be read. What is more, in Firebug, the sent parameters are not human readable.
我收到一条错误消息,指出无法读取 JSON。更重要的是,在 Firebug 中,发送的参数不是人类可读的。
When I try to make an Ajax call with the same parameters, everything seems to be OK:
当我尝试使用相同的参数进行 Ajax 调用时,似乎一切正常:
Ext.Ajax.request({
url:"../search",
method: "POST",
params: JSON.stringify({
rows: pageSize,
role: "Admin",
index: myIndex,
question: searchPhrase
}),
success: function(){
console.log("ok");
},
failure: function(response, opts){
console.log("failed");
},
headers: {
'Content-Type': 'application/json'
}
});
Even in Firebug, every parameter in the request looks just fine.
即使在 Firebug 中,请求中的每个参数看起来都很好。
What does the framework do different when using a Proxy?
使用代理时,框架有何不同?
采纳答案by Dragos
It seems that it is yet another ExtJS issue.
似乎这是另一个 ExtJS 问题。
I have found a fixhere:
我在这里找到了解决方法:
http://www.sencha.com/forum/showthread.php?196194-Ajax-Store-Send-Params-as-JSON-Body
http://www.sencha.com/forum/showthread.php?196194-Ajax-Store-Send-Params-as-JSON-Body
回答by DJDaveMark
I use the following proxy config for the store (ExtJS v6.5.2):
我为商店使用以下代理配置(ExtJS v6.5.2):
proxy: {
url: 'api/search',
paramsAsJson: true,
actionMethods: {
read: 'POST'
},
type: 'ajax',
reader: {type: 'json'}
},
which sends the parameters as JSON:
它将参数作为 JSON 发送:
{"page":1,"start":0,"limit":25}