PDA

View Full Version : How to load data from cross-domain server into store using proxy extjs4



Musa92
31 Mar 2014, 5:41 AM
Hi guys, i am stuck with this problem, so if you could help me?

Problem:
https://stackoverflow.com/questions/22694477/how-to-load-data-from-cross-domain-server-into-store-using-proxy-extjs4

No one answered me yet.

slemmon
2 Apr 2014, 10:48 AM
Hi,

Try setting Ext.Ajax.cors = true; before your application kicks off.

You'll also need to set up CORS on the remote server as well. A resource I've seen come in handy for folks is:
http://enable-cors.org/
or
http://www.html5rocks.com/en/tutorials/cors/

skirtle
2 Apr 2014, 11:43 AM
Do you want to use CORS or JSON-P? Your current config seems to be a mix of the two.

This line implies you're trying to use CORS. It prevents ExtJS adding a custom header, which would force CORS into a pre-flight OPTIONS request:


Ext.Ajax.useDefaultXhrHeader = false;

Similarly, the data returned from your server is JSON, not JSON-P.

However, this line configures a JSON-P proxy:


type: 'jsonp'

If you want to use CORS you'd use an Ajax proxy.

Either way you'll need to write your server to match.

Musa92
3 Apr 2014, 2:35 AM
Hey guys, this helped me! Thanks!


Ext.Ajax.cors = true; is set by default so i didn't have to set it by myself, but i added this code in my server:




app.all('*', function(req, res, next) { res.header("Access-Control-Allow-Origin", "*"); res.header("Access-Control-Allow-Headers", "X-Requested-With"); next(); });

and switch to
type: 'ajax', instead of jsonp