PDA

View Full Version : cannot set json content-type in store



raj_plays
18 Apr 2013, 11:15 AM
Hi,
I am using Ext 3.3.1 with .Net web service(asmx) as server.
When I transfer data in xml format, it works great but when i move to json, it doesnt work.
The problem is the Content-Type for both request and response is always set to "text/xml".
I cannot get it to be "application/json".
Can someone please give a code snippet showing how to set content type in a JsonStore config.
The code below does not work..


var proxy = new Ext.data.HttpProxy({
method: 'POST',
url: 'WebServiceTest.asmx/GetJson',
headers: {
'Content-Type': 'application/json;charset=utf-8'
}
});


var store = new Ext.data.JsonStore({
proxy: proxy,
root: 'd',
idProperty: 'agencyId',
fields: ['agencyId', 'name']
});

If i use the following JQuery code, it works..


$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "WebServiceTest.asmx/GetJson",
dataType: "json",
success: function(msg) {
var obj = jQuery.parseJSON(msg.d);
alert("Total: " + obj.Total);
}
});


What will be the JsonStore equivalent for the above?

mitchellsimoens
22 Apr 2013, 6:19 AM
With your code:


var proxy = new Ext.data.HttpProxy({
method : 'POST',
url : 'data/json.json',
headers : {
'Content-Type' : 'application/json;charset=utf-8'
}
});

var store = new Ext.data.JsonStore({
proxy : proxy,
root : 'd',
idProperty : 'agencyId',
fields : ['agencyId', 'name']
});

store.load();

running it in chrome I see the Content-Type header as is specified:

43280