PDA

View Full Version : JSON in ajax request



dedoz
5 May 2012, 8:57 AM
How to send an ajax request with content type json.

Using Ext Direct proxy on a store/model then doing store.load
sends JSON to the server, the request content type is application/json


Request Headers :
Content-Type:application/json
Request Payload
{"action":"acrQuery","method":"Select","data":[{"page":1,"start":0,"limit":25}],"type":"rpc","tid":4}


how can i archive the same content type using Ext ajax ?
if i use Ext.Ajax (using the same data params above) sends


Request Headers :
Content-Type:application/x-www-form-urlencoded; charset=UTF-8
Form Dataview URL encoded
{"action":"acrQuery","method":"Select","data":[{"page":1,"start":0,"limit":25}],"type":"rpc","tid":4}


its using an html form to send the params, which is correct because documentation says so
but i need to send a request as json (application/json) so i can proceed like i normally do when a store/model sends a request.

so how can i make an ajax request that will use content-type:application/json not a form? like my stores load do.

vietits
5 May 2012, 3:06 PM
Try this:


Ext.Ajax.request({
....
headers: {
'Content-Type': 'application/json',
...
}
....
});

dedoz
8 May 2012, 6:52 AM
thanks