如何使用代理在ext js商店中发布请求时发送JSON

时间:2016-05-27 09:56:30

标签: ajax http extjs extjs6

我是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获得的响应传递给我的商店吗?

1 个答案:

答案 0 :(得分:2)

ExtJS始终将POST值发送为JSON,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:"",
    }
}