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're using Apache just add:
in your configuration. This will cause all responses from your webserver to be accessible from any other site on the internet. If you intend to only allow services on your host to be used by a specific server you can replace the
*
with the URL of the originating server:I will give you a simple solution for this one. In my case I don't have access to a server. In that case you can change the security policy in your Google Chrome browser to allow Access-Control-Allow-Origin. This is very simple:
Simple paste in
"C:\Program Files\Google\Chrome\Application\chrome.exe" --allow-file-access-from-files --disable-web-security
.The location may differ. Now open Chrome by clicking on that shortcut.
If you are using chromer use this plugin
https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi/related?hl=en
This might be handy for anyone who needs to an exception for both 'www' and 'non-www' versions of a referrer:
If you're writing a Chrome Extension and get this error, then be sure you have added the API's base URL to your
manifest.json
's permissions block, example: