facebook

Exception doing HTTP GET on different host in same domain

  1. MyEclipse Archived
  2.  > 
  3. Web 2.0 / AJAX
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #252010 Reply

    dcolemanca
    Member

    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

    #252090 Reply

    Greg
    Member

    Looks 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

Viewing 2 posts - 1 through 2 (of 2 total)
Reply To: Exception doing HTTP GET on different host in same domain

You must be logged in to post in the forum log in