开发者

Xml to HTML5 with javascript

I thought this was a quite common question, but for some reason I can't find the answer anywhere.

I want to read out xml data and put it in my html5 app. The xml file is hosted on a different server. So I've allready got an HTML5 site with layout, I've got t开发者_StackOverflowhe location of my xml file, how do I implement specific data in to my html?


In most browsers, you can't for security reasons. In some newer browsers you can use Cross-Origin Resource Sharing providing the data provider cooperates.

Otherwise you need to make the data available on the same server as the application, or have the data provided in JSON-P format.


For security reasons, you cannot use Javascript to read content from a different domain.

You need to write a server-side script on your domain to forward the XML.
You can then use normal AJAX to create the page.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜