Reputation: 2981
I am trying to create a grid panel using ExtJS 4.1. It gets its data from the server using an AJAX proxy:
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);
but it doesn't seem to work.
I get an error message saying that the JSON could not be read. What is more, in Firebug, the sent parameters are not human readable.
When I try to make an Ajax call with the same parameters, everything seems to be OK:
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'
}
});
Even in Firebug, every parameter in the request looks just fine.
What does the framework do different when using a Proxy?
Upvotes: 5
Views: 21801
Reputation: 2855
I use the following proxy config for the store (ExtJS v6.5.2):
proxy: {
url: 'api/search',
paramsAsJson: true,
actionMethods: {
read: 'POST'
},
type: 'ajax',
reader: {type: 'json'}
},
which sends the parameters as JSON:
{"page":1,"start":0,"limit":25}
Upvotes: 2
Reputation: 2981
It seems that it is yet another ExtJS issue.
I have found a fix here:
http://www.sencha.com/forum/showthread.php?196194-Ajax-Store-Send-Params-as-JSON-Body
Upvotes: 0