我是 ext js 的新手。我正在尝试将请求正文中的 JSON 传递给服务调用。我正在使用以下代码在请求中发送 JSON。我这样做时收到错误响应。
Ext.define('MyStore.store.dashboard.graphs.Temp', {
extend: 'Ext.data.Store',
proxy: {
type: 'ajax',
url: 'abc.php',
headers: {
'Content-Type': 'application/json'
},
params : JSON.stringify({
locationID: [],
startDtTime: "2009-06-10T11:00:00",
endDtTime: "2016-05-10T11:00:00",
GroupValue:"",
}) })
但是当我使用 Ext.Ajax.request 时,我得到了正确的响应:
Ext.Ajax.request({
url: 'abc.php',
jsonData : data,
success: function(hxr) {
console.log(hxr);
},
failure: function(hxr) {
console.log(hxr);
}})
我在论坛上看到过类似的帖子。我的问题是,如果无法使用商店在请求中设置 json,那么我可以将从 Ext.Ajax.request 获得的响应传递到我的商店吗?
最佳答案
ExtJS 总是以 JSON 格式发送 POST 值,except when you submit a form with a file upload field .
But ExtJS store uses GET method for read by default , 而 Ext.Ajax.request
uses POST by default if parameters are defined .
但是您可以明确地告诉商店的代理使用 POST 方法:
proxy:{
actionMethods:{
read:'POST'
},
extraParams : {
locationID: [],
startDtTime: "2009-06-10T11:00:00",
endDtTime: "2016-05-10T11:00:00",
GroupValue:"",
}
}
关于ajax - 如何在使用代理在 ext js 存储中发布请求时发送 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37480418/