I have a data Store that gets it's information from a JSON api on my server. When I run the code in WebKit/Chrome everything appears to work fine, but if I change my user-agent to iPhone 4.1, etc it appears that the JSON requests aren't getting set properly. Instead of sending a request to get JSON it simply sends the request and gets the HTML rendered page instead.
This is the Store that I have defined:
Product.ProductStore = new Ext.data.Store({
model: 'Product',
proxy: {
type: 'ajax',
url: '/admin/products.json',
reader: {
type: 'json',
root: 'products'
}
},
autoLoad: true,
storeId: 'productStore',
getGroupString: function(record){
return record.get('vendor')[0];
}
});
So what I really want to have this store do is send a request to /admin/products.json, which works as expected on the desktop. But when I run this in my Simulator or even on a Device it appears to be just sending the request to /admin/products which returns the HTML instead.
Some people have suggested that this is a rails server issue and I need to set the content type for my request. The problem is how do I exactly do this?
I've tried the following, and it doesn't appear to work either:
Product.ProductStore = new Ext.data.Store({
model: 'Product',
proxy: {
type: 'ajax',
url: '/admin/products.json',
// Trying to set the headers for the request -- not working
headers: {
'Content-Type': 'application/json'
},
reader: {
type: 'json',
root: 'products'
}
},
autoLoad: true,
storeId: 'productStore',
getGroupString: function(record){
return record.get('vendor')[0];
}
});
Could I simply replace the AJAX request with my own that has the content-type headers set properly? If so, are there some examples which use a store and it's own custom AJAX request?
I have a data Store that gets it's information from a JSON api on my server. When I run the code in WebKit/Chrome everything appears to work fine, but if I change my user-agent to iPhone 4.1, etc it appears that the JSON requests aren't getting set properly. Instead of sending a request to get JSON it simply sends the request and gets the HTML rendered page instead.
This is the Store that I have defined:
Product.ProductStore = new Ext.data.Store({
model: 'Product',
proxy: {
type: 'ajax',
url: '/admin/products.json',
reader: {
type: 'json',
root: 'products'
}
},
autoLoad: true,
storeId: 'productStore',
getGroupString: function(record){
return record.get('vendor')[0];
}
});
So what I really want to have this store do is send a request to /admin/products.json, which works as expected on the desktop. But when I run this in my Simulator or even on a Device it appears to be just sending the request to /admin/products which returns the HTML instead.
Some people have suggested that this is a rails server issue and I need to set the content type for my request. The problem is how do I exactly do this?
I've tried the following, and it doesn't appear to work either:
Product.ProductStore = new Ext.data.Store({
model: 'Product',
proxy: {
type: 'ajax',
url: '/admin/products.json',
// Trying to set the headers for the request -- not working
headers: {
'Content-Type': 'application/json'
},
reader: {
type: 'json',
root: 'products'
}
},
autoLoad: true,
storeId: 'productStore',
getGroupString: function(record){
return record.get('vendor')[0];
}
});
Could I simply replace the AJAX request with my own that has the content-type headers set properly? If so, are there some examples which use a store and it's own custom AJAX request?
Share Improve this question asked Mar 15, 2011 at 15:01 csaunderscsaunders 1,7521 gold badge15 silver badges20 bronze badges1 Answer
Reset to default 3It should be
'Accept' : 'application/json'
Accept is a header the client uses to tell the server what media-type it prefers. Content-Type is a header that the server sends as part of the response telling the client what the data is.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745240240a4618138.html
评论列表(0条)