我有兩個頁面:a.example.com和b.example.com一個jQuery的實例,兩個域
a.example.com包括jQuery的
a.example .com包含一個指向的iframe b.example.com
這兩個頁面都將document.domain設置爲相同的父域example.com
如何使用jQuery的包括來自a.example.com調用$阿賈克斯(網址:{url: 「b.example.com」})從B的內部。 example.com iframe?
換句話說:兩個頁面當前都可以訪問彼此的Javascript,但是我不能在不拋出XSS錯誤的情況下使AJAX調用正常工作。也就是說,在b.example.com上也不包括jQuery。我如何避免兩次包含jQuery?
的iframe的內容,例如:
<script>
document.domain = "example.com";
function proxyAjax() {
var jQueryParent = parent.$.sub();
// Chrome gives error: XMLHttpRequest cannot load http://b.example.com/. Origin http://a.example.com/ is not allowed by Access-Control-Allow-Origin.
jQueryParent.ajax({
url : "http://b.example.com/",
success : function() {
console.debug("Success");
}
});
}
proxyAjax();
</script>
你可以給我們一個你想要運行的代碼的例子嗎? – loganfsmyth 2012-01-10 22:46:28