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:
- Instead of requesting a data type of JSON or JSONP, could a request for HTML work, then parse the document response into a JSON object?
- For every request, create and delete an iFrame in page like this poster Using PUT/POST/DELETE with JSONP and jQuery (feels dirty and inelegant)
- Some form of server-side CORS with Username/Password or Token to be sent with the request to allow this (I'm rolling out on iOS first)
- Some other tactic that I can't creatively put my finger on.
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?