跨域XMLHttp请求

发布于 2024-09-08 06:03:22 字数 338 浏览 1 评论 0原文

这是我的情况:

我有一台 Web 服务器机器、一台客户端机器和第三台运行一些侦听 XMLHttpRequest 的程序的机器。

客户端从客户端计算机访问网络服务器,进行一些更改,然后单击“保存”。此时,数据被发送回网络服务器和第三台机器。所有这些都是使用 Javascript 和 XMLHttpRequest 对象完成的。

发布到网络服务器工作正常,但是发布到第三台机器不起作用,因为它有不同的 IP/域。

我怎样才能做到这一点? 客户端机器->第三台机器无法工作,因为它位于不同的域中 网络服务器机器 ->由于防火墙问题,第三台机器无法工作

任何想法都将不胜感激!

Here is my situation:

I have a Webserver machine, Client machine, and a third machine running some program that listens for XMLHttpRequests.

Client accesses the Webserver from the Client machine, makes some changes, and then clicks on'Save'. At this point, data is being sent back to the Webserver and to the Third machine. All of this is being done using Javascript and XMLHttpRequest object.

The post to the Webserver works fine, however post to the Third machine does not work, since it had a different IP/domain.

How can I make this work?
Client machine -> Third machine does not work, because its on a different domain
Webserver machine -> Third machine does not work, because of firewall issues

Any ideas are greatly appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

属性 2024-09-15 06:03:22

您遇到的是同源政策,而不是防火墙问题。

如果计算机共享顶级域,您可以设置其 document.domain要匹配的属性

两个站点共享一个共同的顶级
尽管域可能会选择通信
未能通过“同一主机”检查
相互设定各自的
document.domain DOM 属性
相同合格的右侧片段
他们当前的主机名。

否则,您可能需要设置第一个主机来将请求代理到其他主机

What you're running into is the Same origin policy, not firewall issues.

If the machines share a top-level domain, you can set their document.domain properties to match:

Two sites sharing a common top-level
domain may opt to communicate despite
failing the "same host" check by
mutually setting their respective
document.domain DOM property to the
same qualified, right-hand fragment of
their current host name.

Otherwise, you may need to setup your first host to proxy the request to the other host.

魂ガ小子 2024-09-15 06:03:22

您可以实施 CORS ( 跨源资源共享)在您的服务器上。

当前版本的主要桌面浏览器已经支持它一段时间了,Opera 和 Explorer 10 是最后添加支持的浏览器。

不过,我不确定目前跨移动浏览器对 CORS 的支持有多广泛。

You can implement CORS (Cross-Origin Resource Sharing) on your server.

The current versions of the major desktop browsers have supported it for a while, Opera and Explorer 10 being the last ones to add support.

I'm not sure how widely supported CORS is across mobile browsers at this time though.

陈年往事 2024-09-15 06:03:22

您还可以使用iframe hack。第二个域托管的 iframe 可以在第一个域托管的页面中呈现,并且 窗口iframe 的对象 可以从父页面的上下文中访问。

You could also use the iframe hack. An iframe hosted by the second domain can be rendered in a page hosted by the first domain, and the window object for the iframe will be accessible from the parent page's context.

变身佩奇 2024-09-15 06:03:22

另一种选择(诚然有点技术含量)是如果数据不敏感,则使用 YQL 。您可以使用 YQL 和JSON-P 以便也从其他域获取数据。

Another option (which is admittedly a bit techie) is to use YQL if the data isn't sensitive. You can use YQL & JSON-P in order to fetch data from other domains as well.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文