问题描述
我想申请位于另一个域/服务器上的数据,但是当我尝试发送请求我得到一个例外。
VAR请求=新XMLHtt prequest();
request.open(GET,http://www.w3schools.com/ajax/cd_catalog.xml,假);
request.send();
错误:
这是要求是不一样的域/服务器上的内容的正确方法是什么?或者有没有做到这一点一些其他的方式?
我测试这在Firefox 8.0中,但我想这可能适用于所有主要的现代浏览器的解决方案。
您不能检索直接从其他域的内容。您可以通过服务器检索的内容做的工作适合你(代理),或使用类似JSONP。勾选此维基页面。
有关该主题的额外信息,此页面可能是有趣
I'm trying to request data which is located on another domain/server, but I'm getting an exception when I try to send the request.
var request = new XMLHttpRequest();
request.open("GET", "http://www.w3schools.com/ajax/cd_catalog.xml", false);
request.send();
The error:
Is this the correct way to request content which isn't on the same domain/server? Or is there some other way to accomplish this?
I'm testing this in firefox 8.0, but I'd like a solution that could work for all major modern browsers.
You can't retrieve content from another domain directly. You can retrieve content via a server doing the job for you (proxy), or using something like JSONP. Check this wikipedia page.
For extra information on the subject, this page may be interesting
这篇关于另一个域/服务器上请求的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!