Reputation: 245
I met another strange issue in my work with ExtJS. I get JSON data from my folder myapp/data/users.json but when I change it to URL address pointed to remote server (http://myserver/users.json or .../getusers.php) I get none json data.
My code:
Ext.define('APP.store.Users', {
extend : 'Ext.data.Store',
model : 'APP.model.User',
autoLoad : true,
proxy : {
type : 'ajax',
url : 'http://myserver.com/users.json',
//api : {
// //read : 'data/users.json' // it works OK
//},
actionMethods: {
read: 'GET'
},
extraParams: {
action: 'someaction',
name: 'user'
},
noCache: false,
reader : {
type : 'json',
root : 'users',
successProperty : 'success',
getResponseData : function(r) {
console.log("RESPONSE in reader: ", r);
}
},
afterRequest : function(request, success) {
console.log(request, success); // success: either true or false
},
....
I have installed Apache server to use ExtJS and can load data for localhost/users.json with succ. I thought the problem can make my system. But I checked both for Windows XP and Windows 7 with turned firewall off. It didn't help.
Firebug -> Network shows Http code 200 for the remote address but in respone tab is no data (in this case json structue).
Request headers from Firebug:
Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding gzip, deflate
Accept-Language pl,en-us;q=0.7,en;q=0.3
Access-Control-Request-He... x-requested-with
Access-Control-Request-Me... GET
Connection keep-alive
Host myserver.com // WAS CHANGED
Origin http://localhost
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20100101 Firefox/14.0.1
I have no idea what can be wrogn. All seems to be ok.
Thank you for any hint.
Bogus
Upvotes: 0
Views: 1442
Reputation: 30092
This is covered in the docs:
AjaxProxy cannot be used to retrieve data from other domains. If your application is running on http://domainA.com it cannot load data from http://domainB.com because browsers have a built-in security policy that prohibits domains talking to each other via AJAX.
If you need to read data from another domain and can't set up a proxy server (some software that runs on your own domain's web server and transparently forwards requests to http://domainB.com, making it look like they actually came from http://domainA.com), you can use Ext.data.proxy.JsonP and a technique known as JSON-P (JSON with Padding), which can help you get around the problem so long as the server on http://domainB.com is set up to support JSON-P responses. See JsonPProxy's introduction docs for more details.
Upvotes: 1