2010-08-19 70 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