- This topic has 1 reply, 2 voices, and was last updated 18 years, 7 months ago by Greg.
-
AuthorPosts
-
dcolemancaMemberI 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-GAEclipse SDK
Version: 3.1.2
Build id: M20060118-1600
GregMemberLooks like you have to tell Mozilla that you want to perform cross-domain scripting. A quick google search returned at least some interesting information.
http://www.captain.at/howto-ajax-permission-denied-xmlhttprequest.php -
AuthorPosts