Reputation: 140
I am new to ext js. I am trying to pass a JSON in the request body to service call. I am using the following code to send JSON in the request. I getting an error response when i do so.
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:"",
}) })
But when i use Ext.Ajax.request i get a proper response:
Ext.Ajax.request({
url: 'abc.php',
jsonData : data,
success: function(hxr) {
console.log(hxr);
},
failure: function(hxr) {
console.log(hxr);
}})
I have seen similar posts in the forums. My question is if there is no way to set json in a request using store then can i pass response obtained from Ext.Ajax.request to my store?
Upvotes: 1
Views: 4181
Reputation: 20224
ExtJS always sends POST values as JSON, except when you submit a form with a file upload field.
But ExtJS store uses GET method for read by default, while Ext.Ajax.request
uses POST by default if parameters are defined.
But you can explicitly tell the store's proxy to use the POST method:
proxy:{
actionMethods:{
read:'POST'
},
extraParams : {
locationID: [],
startDtTime: "2009-06-10T11:00:00",
endDtTime: "2016-05-10T11:00:00",
GroupValue:"",
}
}
Upvotes: 2