views:

766

answers:

1

I have website that use XMLHttpRequest (jQuery, actually). I also have another site running on the same server, which serves a script file that makes XHR requests back to THAT site, ie.

http://mysite:50000/index.html includes

<script src="http://mysite:9000/otherscript.js"&gt;&lt;/script&gt;

and http://mysite:9000/otherscript.js includes

$.ajax({
    url: 'http://mysite:9000/ajax/stuff'
});

The problem is - this doesn't work. The AJAX requests from the loaded script simply fail with no error message. From what I've been able to find this is the old same origin policy. Given that I control both sites, is there anything I can do to make this work? The "document.domain" trick doesn't seem to do a thing for XMLHttpRequest.

+1  A: 

Nope- can't do this with XHR. Same-domain policy is very restrictive there- same host, same port, same protocol. Sorry! You'll have to resort to other tricks (iframes, title manipulation, etc) to get it to work.

nitzmahone
What is the "title manipulation" trick?
Evgeny
If you have signed javascript you can do this on FF.
bmargulies
See http://dannythorpe.com/2008/07/28/cross-domain-transport-with-windowname/ and http://orensol.com/2009/06/07/cross-domain-ajax-calls-and-iframe-communication-how-to/ for examples. There are jQuery and dojo addons that wrap this stuff up nicely.
nitzmahone
Here's a jQuery plugin that wraps it up- I've seen several others but can't lay my hands on them now: http://friedcellcollective.net/outbreak/jsjquerywindownameplugin/
nitzmahone
The window.name plugin looked very promising, but unfortunately it also fails to work. :(
Evgeny
nitzmahone