我正在尝试使用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);
但它似乎不起作用。
我收到一条错误消息,指出无法读取JSON。更重要的是,在Firebug中,发送的参数不是人类可读的。
当我尝试使用相同的参数进行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'
}
});
即使在Firebug中,请求中的每个参数也都很好。
使用代理时框架有何不同之处?
答案 0 :(得分:0)
这似乎是另一个ExtJS问题。
我在这里找到了修复:
http://www.sencha.com/forum/showthread.php?196194-Ajax-Store-Send-Params-as-JSON-Body
答案 1 :(得分:0)
我为商店使用以下代理配置(ExtJS v6.5.2):
proxy: {
url: 'api/search',
paramsAsJson: true,
actionMethods: {
read: 'POST'
},
type: 'ajax',
reader: {type: 'json'}
},
以JSON格式发送参数:
{"page":1,"start":0,"limit":25}