I'm creating a web app (using phonegap) that needs to retrieve an xml document from an online site. How do I do this? From what i gather, AJAX will only work on relative url's due to some security restriction...
You can query a PHP script on your server using AJAX that returns the XML content using something like file_get_contents or PHP XML SimpleXML:
have you tried to work with JQuery
ajax api? You will have to make the crossDomain
option to true
so that you can do a crossdomain request. Also, you will have to add the site to your white list domains in the PhoneGap plist
file.
PhoneGap doesn't subject your code to the same-origin policy which prevents you from using AJAX cross-domain:
Q. I want to create an application for phonegap to access externally deployed web services via AJAX. How can i resolve the issue with the cross-domain security policy of XmlHttpRequest?
A. The cross-domain security policy does not affect PhoneGap applications. Since the html files are called by webkit with the file:// protocol, the security policy does not apply.
(in Android,you may grant android.permission.INTERNET to your app by edit the AndroidManifest.xml)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.