View Full Version : One JsonStore not sending request with correct content type header

29 Jun 2010, 8:39 PM
For the life of me, I can't figure out why one of my JsonStores is not sending Content-type as "application/json", but rather "text-html". In the one that is working, I'm not even specifying a proxy. In the one that's not working, I tried also specifying a proxy with headers config, but it seems to ignore it.

Anyone have any ideas why this might be happening?

29 Jun 2010, 9:20 PM
You can't configure Proxies with headers.

Connections you can

30 Jun 2010, 6:25 AM
So given the following code, how to I specify the Content-type: "application/json"?

store: new Ext.data.JsonStore({
url: "somepage.aspx",
autoLoad: false,
sortInfo: {
field: 'date',
direction: 'DESC'
root: 'd',
id: 'id',
fields: [
{ name: 'id' },
{ name: 'from' }

30 Jun 2010, 6:44 AM
Is the server really concerned with seeing that header though?

30 Jun 2010, 6:56 AM
yes, because ASP.NET will format the output accordingly. If I want JSON output, you have to explicitly set Content-type: "application/json", otherwise, it does XML. Yes, I could format the output myself manually into JSON from within the ASP.NET page, but I just prefer to let ASP.NET do it itself.

30 Jun 2010, 7:16 AM
I think you can change the defaultHeaders of the connection to send "application/json" always?!? Or does it need to be specific to each request?

30 Jun 2010, 7:20 AM
You sure you don't mean the Accept header?

Content-Type means the content type being sent.

But anyway

MyRecord = Ext.data.Record.create([
{ name: 'id' },
{ name: 'from' }
var store = new Ext.data.Store({
proxy: new Ext.data.HttpProxy(new Ext.data.Connection({
url: 'somepage.aspx',
defaultHeaders: {
'Content-Type': 'application/json'
reader: new Ext.data.JsonReader({
idProperty: 'id',
root: 'd'
}, Myrecord)

30 Jun 2010, 7:20 AM
As default is fine. But how do you reference the connection object from my sample code above?

30 Jun 2010, 8:56 AM
Animal probably solved your question. The answer to the other question you posed is: there is a "conn" accessible property in HttpProxy.