...

View Full Version : Permission denied to call method XMLDocument.load



sir pannels
05-09-2007, 03:21 PM
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 ..



xmlDoc=document.implementation.createDocument("","",null);
xmlDoc.load("http://127.0.0.1/data.xml");


Any thoughts?
Thanks very much,
Sir P :D

david_kw
05-09-2007, 03:24 PM
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

sir pannels
05-09-2007, 03:28 PM
Hi David,

Thanks for you reply.

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

Cheers,
Sir P

david_kw
05-09-2007, 04:37 PM
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 (http://en.wikipedia.org/wiki/Same_origin_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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum