2010-08-19 72 views
1

我知道,由于JavaScript安全沙箱,从JavaScript代码所在的域之外加载xml数据是不可能的。JavaScript&XMLHttpRequest

但如果我使用本地主机:8080和XML文件从本地主机来在同一台机器但是从另一个端口像8081,这个被认为是相同的域或不?

感谢

安迪e和肯·雅各,谢谢大家:-)

+0

jsonp是解决这个问题的方法。您在查询字符串中插入带回调的脚本标记。脚本执行时,它会调用通过返回的xml作为参数的回调函数。 – 2010-08-19 18:22:40

回答

5

不同的端口被认为是“不同产地”,从而违反了同源策略。

 
URL            Outcome Reason 
================================================================================= 
http://store.company.com/dir2/other.html   Success 
http://store.company.com/dir/inner/another.html Success 
https://store.company.com/secure.html    Failure Different protocol 
http://store.company.com:81/dir/etc.html   Failure Different port 
http://news.company.com/dir/other.html    Failure Different host 

来源(S):Same origin policy for JavaScript - MDCSame origin policy - Wikipedia