2007.0722
用document.domain解决Ajax跨子域

因为浏览器的安全策略,浏览器不允许不同域(比如:dancewithnet.com和lab.dancewithnet.com)、不同协议(比如:http://dancewithnet.com和https://dancewithnet.com)、不同端口(比如:http:dancewithnet.com和http://dancewithnet.com:8080)下的页面通过XMLHTTPRequest相互访问,这个问题同样影响着不同页面的Javascript的相互调用和控制,但是当主域、协议、端口相同时,通过设置页面的document.domain主域,Javascript可以在不同的子域名间访问控制,比如通过设置document.domain=’dancewithnet.com’,http://dancewithnet.com和http://lab.dancewithnet.com页面可互访,这个特性也提供了此情况下不同子域名下的XMLHTTPRequest相互访问的解决方案。

阅读全文 »

标签:, ,
在17:38发表于Javascript & DOM & AJAX,有评论6
回到页眉