问题描述
比方说,我有一个从 http://www.example.com/index.html 加载主页。该网页上有JS code,使一个Ajax请求 http://n1.example.com//回音?消息=你好。当响应收到一个div主页上的响应体将被更新。
Let's say I have the main page loaded from http://www.example.com/index.html. On that page there is js code that makes an ajax request to http://n1.example.com//echo?message=hello. When the response is received a div on the main page is updated with the response body.
将在所有流行的浏览器的工作?
Will that work on all popular browsers?
编辑:
显而易见的解决方案是把一个代理在www.example.com和n1.example.com的前面,设置它让每一个请求会的的被代理到 http://n1.example.com/ 。
The obvious solution is to put a proxy in front of www.example.com and n1.example.com and set it so that every request going to a subresource of http://www.example.com/n1 gets proxied to http://n1.example.com/.
推荐答案
跨域完全是一个不同的主题。但跨子域是比较容易的。所有你需要做的是设置document.domain的是在这两个父页面和iframe的页面一样。
Cross domain is entirely a different subject. But cross sub-domain is relatively easy. All you need to do is to set the document.domain to be same in both the parent page and the iframe page.
document.domain = "yourdomain.com"
这里
这篇关于有关跨域(子域)Ajax请求的一个问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!