SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Mar 2006
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    XMLHttpRequest.open permission denied

    I have three very simple files:
    test_parent.html,
    test_child.html, and
    simple_script.php.
    All three are located on the same domain, in the same directory.

    test_child.html simply displays a button, that, when pressed, makes an asychronous request to simple_script. When the request successfully comes back, test_child.html throws up an alert message. This works with no problems.

    test_parent.html also simply displays a button. However, this button triggers window.open(), which opens test_child.html. test_child.html successfully opens and displays its button, but its button no longer works. Now I get the error message: "uncaught exception: Permission denied to call method XMLHttpRequest.open".

    This happens on the Mac version of Firefox. It does NOT happen on Safari. I don't know if it happens on the Windows version of Firefox.

    I've seen online explanations that this error occurs when a page tries to asynchronously access a script on another domain. Here, however, not only is everything on the same domain, it's in the same directory!

    Can anybody help? Specifically, can anybody
    1) also confirm that this happens to them
    2) explain WHY this is happening, and, most important,
    3) suggest a fix of some kind?

    OH I'd be so grateful if somebody could help me. Here are the files:


    +++ simple_script.php++++++++++++++++
    <?
    echo $_POST['data'];
    ?>
    +++++++++++++++++++++++++++




    ++++ test_child.html ++++++++
    <html>
    <head>

    <script>
    request = new XMLHttpRequest();
    function postData() {
    var url = "simple_script.php";
    request.open("POST", url, true);
    request.onreadystatechange = showAlert;
    request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    request.send('data=This is a test');
    }

    function showAlert() {
    if (request.readyState == 4) {
    if (request.status == 200) {
    alert(request.responseText);

    }
    }
    }
    </script>
    </head>

    <body>
    <button id="saveButton" type="button" onclick="postData()">Post</button>
    </body>
    </html>
    ++++++++++++++++++++++++++++




    +++++++ test_parent.html +++++++++++
    <html>
    <head>
    </head>

    <body>
    <button type="button" value="Open Window" onclick="window.open('test_child.html')">Open Window</button>
    </body>
    </html>
    ++++++++++++++++++++++++++++

    Thanks,
    Robbie

  2. #2
    SitePoint Addict
    Join Date
    Oct 2006
    Posts
    210
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not sure what the problem is but, as a test, I'd modify test_child to use a full URL (http://hostName/simple_script.php). If this works, then the XMLHttpRequest object thinks the domain names are different. But I don't know why it would think that.

  3. #3
    SitePoint Member
    Join Date
    Mar 2006
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by mikemckinney View Post
    Not sure what the problem is but, as a test, I'd modify test_child to use a full URL (http://hostName/simple_script.php). If this works, then the XMLHttpRequest object thinks the domain names are different. But I don't know why it would think that.
    Hi Mike,
    Thanks for the reply. I tried what you suggested in test_child, but no change.

    Based on your suggestion I also tried this: Instead of modifying the URL in test_child , I changed the url argument inside window.open() in test_parent to a full absolute path. Intitially, this also did nothing. HOWEVER, (keeping in mind I'm still in test_parent, here) I tried changing the domain name from 127.0.0.1 to "localhost" (I'm working on this on my local development server). This time button in the javascript-opened test_child page now successfully makes the asynchronous request without an error message.

    I also tried the opposite- I opened test_parent in the browser window using a URL with the domain name "localhost" while setting the window.open() arguemnt to use a full url with the 127.0.0.1 domain name. This also worked.

    Summary so far: If the URL that shows in the browser window of test_parent reflects a DIFFERENT domain name from that used as the argument for the window.open(), (even though the domains are not really different i.e., in this case, 127.0.0.1 and "localhost"), the button-triggered window.open() will open a test_child page which is able to call XMLHttpRequest.open. However, if the domain is referenced each time using the SAME name, an error message appears claiming that no permission exists to call XMLHttpRequest.open.

    Although this is perhaps useful information, the problem is still not fixed. Drat!

    Any other suggestions? Anyone?

    I should mention this too: although I'm talking about dealing with this problem on my local server, I also uploaded the pages to my remote website. The problem occurs there too.

    Thanks,
    Robbie

  4. #4
    SitePoint Addict
    Join Date
    Oct 2006
    Posts
    210
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You should be aware that for lots of programs (and maybe most) a host name is a string. So '127.0.0.1' would not be the same as 'localhost' even though both resolve to the same IP address. I'm surprised that it works when one URL uses 127.0.0.1 and the other uses localhost. I'm also surprised that it fails on your remote server.

    I'd have the test_child window display its window.location value to see what it thinks is its full URL. That may give you a clue.

  5. #5
    SitePoint Member
    Join Date
    Mar 2006
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by mikemckinney View Post
    You should be aware that for lots of programs (and maybe most) a host name is a string. So '127.0.0.1' would not be the same as 'localhost' even though both resolve to the same IP address. I'm surprised that it works when one URL uses 127.0.0.1 and the other uses localhost.
    Exactly. When the URLs show a different hostname, it works. But when they're the same, it doesn't work. This is completely contrary to what might be expected. It doesn't make any sense at all.


    Quote Originally Posted by mikemckinney View Post
    I'd have the test_child window display its window.location value to see what it thinks is its full URL. That may give you a clue.
    Thanks for the suggestion. Unfortunately, nothing unusual in what the window thinks is its url. window.location displays exactly what appears in the browser URL field.

    To sum up this problem again even more concisely:
    When the page is opened the ordinary way- that is, by typing a url in the browser window and pressing enter, the page pops up and is able to call XMLHttpRequest.open without error.
    But when the page is opened via another page running the script window.open(), something less than perfect pops up- the page looks ok and for the most part scripts work (as far as I know), BUT for some reason this page is not normal- it lacks "permission" to run XMLHttpRequest.open.

    This is infinitely peculiar. What would be different about a page opened the manually, and one opened via window.open()? That's the crux of this problem.

    If there is anybody out there running the Mac version of Firefox, could you confirm one way or the other if, when you run these files, you get this same error?

    Thanks,
    Robbie

  6. #6
    SitePoint Addict
    Join Date
    Oct 2006
    Posts
    210
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm running Mac Firefox 2.0 and it works! Try the following URL:

    http://aldencabinetry.com/test_parent

  7. #7
    SitePoint Member
    Join Date
    Mar 2006
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thanks, Mike!

    Mike,
    Thanks so much for taking the trouble to upload those files to your site. I clicked your link and, on this computer (4-year old PowerBook) it STILL doesn't work, but thanks to you letting me know that it works for you, at least I know that there's nothing wrong with this code on Mac Firefox.

    I should have tried this from the beginning, but I fired up my old 400 Mhz G4 and downloaded the latest version of Firefox and clicked your link and found on that machine, as you also found on yours, it works!!

    I still have no idea why it doesn't work on this Powerbook, but dealing with that problem is much better than trying to figure out why my code doesn't work on Firefox. Thanks to your help I know know it does.

    Incidentally, I tried restarting the PowerBook, and also I downloaded the latest update for Firefox- I discovered that I was using version 2.0 instead of the latest- 2.0.0.1, but nevertheless it still doesn't work on this PowerBook.

    Thanks again!

    Robbie


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •