I'm building a mobile app with PhoneGap and I need it to fit into my services RESTful api.
Basically if I want to retrieve/delete/update/check/(nonidempotent action) the resource, issuing a GET/DELETE/PUT/HEAD/POST request via jQuery's ajax method to http://example.com/resource/:id is supported. This is where I'm running into the issue.
Since PhoneGap holds files and serves them locally (e.g: file://file.html), I'll have cross domain issues with the ajax call. Additionally, I understand that JSONP is basically inserting a script into the document, therefore is a solution to one method of request
Here are some ideas:
What's the most elegant solution to this problem? Plugins are welcome.
TL;DR: How do I add cross-domain support on $.ajax requests for different HTTP Methods?
You have to white-list your server in the PhoneGap properties. By default, PhoneGap restricts access to external sites to prevent security issues. PhoneGap does not have cross-domain issues like standard http-hosted sites. Read here for details: http://docs.phonegap.com/en/2.1.0/guide_whitelist_index.md.html#Domain%20Whitelist%20Guide