I'm making an Ajax.request
to a remote PHP server in a Sencha Touch 2 application (wrapped in PhoneGap).
The response from the server is the following:
XMLHttpRequest cannot load http://nqatalog.negroesquisso.pt/login.php. Origin
http://localhost:8888
is not allowed by Access-Control-Allow-Origin.
How can I fix this problem?
If you don't have control of the server, you can simply add this argument to your Chrome launcher:
--disable-web-security
.Note that I wouldn't use this for normal "web surfing". For reference, see this post: Disable same origin policy in Chrome.
One you use Phonegap to actually build the application and load it onto the device, this won't be an issue.
If you have an ASP.NET / ASP.NET MVC application, you can include this header via the Web.config file:
In Ruby on Rails, you can do in a controller:
In Ruby Sinatra
for everyone or
When you receive the request you can
than when you have to response go with something like that:
The wildcard isn't a very safe option. You'd want it to be more specific - checkout the answer I've written here on the same question; how to bypass Access-Control-Allow-Origin?