通过Javascript加载跨域xml
嗨
是否可以使用纯 javascript 从与脚本域不同的域加载 XML 文件,而不使用 php/asp/jsp/... 脚本作为代理?
类似于 xmlHttpRequest 但能够管理跨域请求。
谢谢
Hi
Is it possible to load an XML file from a domain that differs from scripts domain with pure javascript and without using a php/asp/jsp/... script as proxy?
Something like xmlHttpRequest but with ability to manage cross domain requests.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用称为 JSONP 的东西。我知道这个名字很糟糕,因为它与 JSON 并没有真正的关系。但这需要您拥有对其他域的控制权。您需要将 XML 包装在函数调用中,或将其分配给 javascript 变量:
func(' ');
或
var myxml = '< ;xml>';
因此,如果您的其他域返回这两种格式之一,您可以使用
You can use something called JSONP. I know the name sucks, because it's not really related to JSON. But this requires you have control over the other domain. You need to wrap your XML inside a function call, or assign it to a javascript variable:
func('<xml></xml>');
or
var myxml = '<xml></xml>';
So if your other domain returns one of these two formats, you can use the
<script src="http://otherdomain/yourjsonp"></script>
syntax in your html to load that data in JavaScript. It's a little hacky but a lot of people use it.用yql就可以了! (雅虎为您做到了)
转到 这个网站和简单的“select from url='xxx'”将xxx替换为您的xml url。使用在下面的文本框中创建的 url 并执行一个简单的 xml 请求。您不会有任何跨域问题
It is possible with yql! (Yahoo did it for you)
Go to this site and simple at the "select from url='xxx' " replace the xxx with your xml url. Use the url created at the text box below and do a simple xmlrequest. You won't have any cross-domain prolems