views:

402

answers:

4

What would I need to do to get this example running on my machine?

http://www.w3schools.com/ajax/tryit.asp?filename=tryajax%5Fhttprequest%5Fjs

I'm looking to access the XML file hosted on w3schools (and not move it to my machine), but run the HTML and Javascript code on my machine. I tried changing the third to last line from:

<button onclick="loadXMLDoc('note.xml')">Get XML</button>

to:

<button onclick="loadXMLDoc('http://www.w3schools.com/ajax/note.xml')"&gt;Get XML</button>

thinking this would make it work, but it didn't seem to help. Any suggestions?

+3  A: 

Just put the full URL into your browser window which will let your browser get it, then copy/paste and save locally. Javascript won't fetch stuff from outside the domain it's served from (without a fair bit of extra work), due to the Same Origin policy ( a security feature).

Paul
what's the extra work?
Mark
+1  A: 

You can't go cross domain using AJAX. You should move the XML file to the same server that you have the site files stored on and call it that way.

Corv1nus
A: 

You need to use the following code in the function that does the AJAX:

  try {
    netscape.security.PrivilegeManager.enablePrivilege("UniversalPreferencesRead");   
  } catch (e) {
    alert("error");
  }

This only works for Firefox! There are other options which can be passed to enablePrivilege that may be useful.

Mark