Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Posts
    905
    Thanks
    23
    Thanked 5 Times in 5 Posts

    Permission denied to call method XMLDocument.load

    Hi all,

    I'm trying to load an XML file using DOM via JS however having some problems. Works in all browsers other than firefox.

    The problem is, if I try to access a XML file on remote machine firefox says "Error: uncaught exception: Permission denied to call method XMLDocument.load"

    Works on IE and Opera as I said. The code Im using ..

    Code:
    	xmlDoc=document.implementation.createDocument("","",null);
    	xmlDoc.load("http://127.0.0.1/data.xml");
    Any thoughts?
    Thanks very much,
    Sir P

  • #2
    Senior Coder
    Join Date
    Nov 2006
    Posts
    1,000
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It is my understanding of the security model that you cannot give full absolute URLs to load(). You can only load from your own same-origin server so have to use a relative path like

    xmlDoc.load("/data.xml");

    I'm surprised it works in the other browsers.

    david_kw

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Posts
    905
    Thanks
    23
    Thanked 5 Times in 5 Posts
    Hi David,

    Thanks for you reply.

    If that is the case, how do RSS feeds and so forth work ? :s

    Cheers,
    Sir P

  • #4
    Senior Coder
    Join Date
    Nov 2006
    Posts
    1,000
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I've never written one myself but my understanding is they can be done in a number of ways. One way is to use the xml.load() function but proxy the rss feed on your own server so it doesn't violate the same-origin security policy.

    Another way is to "trick" the browser into getting data from another site by adding a <script> tag dynamically to the your html page. The script is loaded and the javascript is parsed. If the javascript has something like

    var textResponse = "<books><book><title>...";

    Then when the parsing is finished that xml text will be available for parsing into an xml dom object. Usually this system uses a callback function to say when the <script> tag has been loaded and parsed. I suspect this is how Google does it (although I haven't looked at the source to find out).

    http://code.google.com/apis/ajaxfeeds/documentation/

    david_kw


  •  

    Posting Permissions

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