ExtJS Ajax POST vs Proxy POST
ExtJS Ajax POST vs Proxy POST
我正在尝试使用 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 中,请求中的每个参数看起来也很好。
使用代理时,框架有什么不同?
我对存储使用以下代理配置(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}
这似乎是另一个 ExtJS 问题。
我在这里找到了一个修复程序:
http://www.sencha.com/forum/showthread.php?196194-Ajax-Store-Send-Params-as-JSON-Body
相关文章:
- 如何使用WCF服务和javascript表单post上传.doc文件
- Jquery POST未填充数组
- 如何在php文件中获取$.post-ajax传递的值
- 在POST中将html表作为csv提交
- JS表单提交"无法使用Chrome数据保护程序加载此页面.尝试重新加载页面.调试信息:POST CISmtuK
- 如何使用post方法从方法上传文件
- Django: AJAX + CSRF POST gives 403
- AJAX不会在文件上传后重定向到网页-POST方法
- 下载使用POST数据动态生成的文件
- 如何使用自定义标头跨域执行AJAX POST
- 错误405:向Java控制器(Ajax)发送JSON时找不到POST方法
- jQuery在输入下验证post错误消息
- 在文本区域POST后解码JSON
- Node.js - POST to iFrame?
- 中止POST XHR可靠
- 当method=post时,jQueryAjax返回404
- 当我在form_for中的text_field_tag中点击Enter时,如何禁止发出POST请求
- 为什么 AJAX POST 请求不起作用
- 如何从HTTP上下文对象中获取Post数据
- ExtJS Ajax POST vs Proxy POST