I am unable to open an HTTP request to a different server in the same domain when debugging a Javascript. It seems to be related to the same-origin restriction of cross-site scripting, but I can execute the same code on Internet explorer and get the expected response from âanotherhost.abc.comâ
My HTML page is for example hosted at âmyhost.abc.comâ, but I want to do a âGETâ on âanotherhost.abc.comâ.
By doing the following Javascript, I can allow the script to go to other hosts in the same domain:
document.domain = âabc.comâ;
I am actually doing stuff with Google Maps so I am using their convenient object GXmlHttp, but underneath the hood they are creating an XMLHttpRequest object.
So hereâs the code that works on IE 6 but does not work when debugging from MyEclipse:
var http_request = GXmlHttp.create();
if (!http_request) {
alert(“Giving up đ Cannot create an XMLHTTP instance”);
return false;
}
http_request.onreadystatechange = function () {
alertContents(http_request);
};
http_request.open(“GET”, âhttp://anotherhost.abc.com:8080/file.kmlâ, true);
The last line gives the following exception in the Javascript Console:
ââPermission denied to call method XMLHttpRTequest.openâ when calling method: [nsIDOMEventListener::handleEvent]â nsresult: â0x8057001e (NS_ERROR_XPC_JS_THREW_STRING)â location: â<unknown>â data: no]
My config is as follows:
MyEclipse
Version: 4.1.1
Build id: 20060309-4.1.1-GA
Eclipse SDK
Version: 3.1.2
Build id: M20060118-1600