JavaScript的 - 要访问与阿贾克斯另一个域的内容是什么? [英] javascript - Want to access the contents of another domain with ajax?
问题描述
我想写一个JavaScript应用程序,从OpenStreetMap的API加载数据( HTTP:/ /wiki.openstreetmap.org/wiki/OSM_Protocol_Version_0.6 ),这基本上是一个宁静的XML API。我试图使用jQuery来访问XML。但是我得到的安全错误。这是一个跨站点脚本拦截。
I'm trying to write a javascript application that loads data from the openstreetmap API (http://wiki.openstreetmap.org/wiki/OSM_Protocol_Version_0.6), which is basically just a restful xml api. I'm trying to use jquery to access the XMl. however I get security errors. This is a cross site scripting blocking.
我如何访问XML? AFAIK OSM不提供JSONP,这样是行不通的。有没有呢?>
How can I access that XML? AFAIK OSM don't offer jsonp, so that doesn't work. Is there anyway?>
推荐答案
本博客文章由丹联展示了如何解决这个问题,但这里的背景:
The blog post linked by Dan shows you how to solve this problem, but here's the background:
您可以从网页中的跨域JavaScript调用的唯一方法是通过JSONP。如果你不提供JSONP,那么你将不得不求助于使用代理脚本,因为浏览器有目的地$作出这样的调用p $ pvent站点脚本。
The only way you can make a cross-domain Javascript call from a web page is via JSONP. If you aren't offered JSONP, then you will have to resort to using a Proxy script, as browsers purposefully prevent site scripts from making such calls.
请注意,如果你正在写你所运行的特权空间中的Firefox扩展,从而能够无限制地进行这种跨域调用。
Note that if you're writing a Firefox extension you are executing in a privileged space, and thus are able to make such cross-domain calls without restrictions.
这篇关于JavaScript的 - 要访问与阿贾克斯另一个域的内容是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!