Cross-domain Ajax requests
MARCH 11, 2011
Before you get any hopes (or worries), the following is just a technique that comes handy for development, not for production.
I’m developing a PhoneGap app with Sencha Touch. The app needs to do a few Ajax POST requests to a different domain. You can do that without problems from your PhoneGap app.
Though, the development environment of choice for a Sencha Touch developer is the browser. Browsers don’t let you do that, at least not by default. (You can do cross-domain GET requests easily via JSONP.)
By default, the browser, WebKit in this case, returns the following error: XMLHttpRequest cannot load URL. Origin http://localhost is not allowed by Access-Control-Allow-Origin.
Though, you can easily disable that security policy by opening the browser with –disable-web-security.
So, if you’re using Google Chrome on a Mac for development, run the following in the Terminal:
open /Applications/Google\ Chrome.app –args –disable-web-security
