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?
JSON.stringify
fromextraParams
- it work well for me just sending an object. 2) to be on the safe side, try to include the proxy configwriter: 'json'
. 3) comment theheaders
config. – IzhakiJSON.stringify
, then I get another error(I found this method to avoid it somewhere on the internet). If I comment theheaders
config, then a wrongcontent-type
is being set(again, a problem). Regarding the response, I do not think that there lies the problem, since I get a 302 status and the error(Could not read JSON
) comes from the server. Any other suggestions? – DragosJSON.stringify
you get a really odd request full of escaped chars (%XX). I'm sorry to say but I think the problem is server side and not ExtJS. – IzhakiJSON.stringify
on the simple Ajax call works great(the request looks as it should), but it looks awful when used with the store. Why? RemovingJSON.stringify
is not an option. – Dragos