简体   繁体   English

从外部站点下载XML

[英]Download XML from external site

I'm creating a web app (using phonegap) that needs to retrieve an xml document from an online site. 我正在创建一个需要从在线站点检索xml文档的Web应用程序(使用phonegap)。 How do I do this? 我该怎么做呢? From what i gather, AJAX will only work on relative url's due to some security restriction... 从我收集的内容来看,由于某些安全限制,AJAX只能处理相对url ...

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: 您可以使用AJAX查询服务器上的PHP脚本,该脚本使用类似file_get_contents或PHP XML SimpleXML的方式返回XML内容:

http://www.w3schools.com/PHP/php_xml_simplexml.asp http://www.w3schools.com/PHP/php_xml_simplexml.asp

have you tried to work with JQuery ajax api? 你试过使用JQuery ajax api吗? You will have to make the crossDomain option to true so that you can do a crossdomain request. 您必须将crossDomain选项设置为true以便您可以执行crossDomain请求。 Also, you will have to add the site to your white list domains in the PhoneGap plist file. 此外,您必须将该站点添加到PhoneGap plist文件中的白名单域。

PhoneGap doesn't subject your code to the same-origin policy which prevents you from using AJAX cross-domain: PhoneGap不会将您的代码置于同源策略中,这会阻止您使用AJAX跨域:

Q. I want to create an application for phonegap to access externally deployed web services via AJAX. 问:我想为phonegap创建一个应用程序,以通过AJAX访问外部部署的Web服务。 How can i resolve the issue with the cross-domain security policy of XmlHttpRequest? 如何使用XmlHttpRequest的跨域安全策略解决问题?

A. The cross-domain security policy does not affect PhoneGap applications. 答:跨域安全策略不会影响PhoneGap应用程序。 Since the html files are called by webkit with the file:// protocol, the security policy does not apply. 由于webkit使用file:// protocol调用html文件,因此安全策略不适用。

(in Android,you may grant android.permission.INTERNET to your app by edit the AndroidManifest.xml) (在Android中,您可以通过编辑AndroidManifest.xml将android.permission.INTERNET授予您的应用)

From http://wiki.phonegap.com/w/page/16494770/FAQ 来自http://wiki.phonegap.com/w/page/16494770/FAQ

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM