cross domain XMLHttprequest

元气小坏坏 提交于 2019-12-05 10:38:57

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.

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.

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!