Skip to main content

One jQuery Instance, Two Domains



I have two pages: a.example.com and b.example.com





a.example.com includes jQuery





a.example.com contains an iframe pointing to b.example.com





both pages have document.domain set to the same parent domain, example.com





How can I use the jQuery include from a.example.com to call $.ajax({ url: " b.example.com " }) from inside the b.example.com iframe?





In other words: Both pages can currently access the Javascript of one another, but I can not get the AJAX call to function without throwing XSS errors. That is, without including jQuery on b.example.com too. How do I avoid including jQuery twice?





Example of the contents of the 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>




Comments

Popular posts from this blog

Slow Android emulator

I have a 2.67 GHz Celeron processor, 1.21 GB of RAM on a x86 Windows XP Professional machine. My understanding is that the Android emulator should start fairly quickly on such a machine, but for me it does not. I have followed all instructions in setting up the IDE, SDKs, JDKs and such and have had some success in staring the emulator quickly but is very particulary. How can I, if possible, fix this problem?