另一个域/服务器上请求的内容 [英] request content on another domain/server

查看:78
本文介绍了另一个域/服务器上请求的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想申请位于另一个域/服务器上的数据,但是当我尝试发送请求我得到一个例外。

  VAR请求=新XMLHtt prequest();
request.open(GET,http://www.w3schools.com/ajax/cd_catalog.xml,假);
request.send();
 

错误:

未捕获的异常:[异常...组件返回故障code:0X80004005(NS_ERROR_FAILURE)nsresult:0X80004005(NS_ERROR_FAILURE)]

这是要求是不一样的域/服务器上的内容的正确方法是什么?或者有没有做到这一点一些其他的方式?

我测试这在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:

uncaught exception: [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE)" nsresult: "0x80004005 (NS_ERROR_FAILURE)"]

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

这篇关于另一个域/服务器上请求的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆