Philip
Philip

Reputation: 59

Xml to js code problem

So i'm very new to xml to javascript so i thought I would learn from w3schools, but this site http://www.w3schools.com/xml/xml_to_html.asp shows an example that I can't mimic locally. I copy/pasted the .js and downloaded the xml but I just get a blank screen!

It's working in there try it yourself but not for me? Do I need it on a server or something?

Upvotes: 1

Views: 146

Answers (4)

David Tang
David Tang

Reputation: 93674

Yes, that code retrieves the XML data from a web server using AJAX. Since you don't have a server running locally, you can change the URL to point directly to the w3school's version:

xmlhttp.open("GET","http://www.w3schools.com/xml/cd_catalog.xml",false);

Alternatively, play around on their online version ;)

Upvotes: 1

stef
stef

Reputation: 14268

Are you running this under a web server or just creating a couple of text files and loading them in your browser?

The "GET" request this relies upon could possibly be failing.

Use Apache or another similar HTTP server and run the example as if it were hosted on the web.

Upvotes: 0

volpav
volpav

Reputation: 5128

First, ensure that both HTML file (with the Javascript block in it) and XML file are placed in the same directory.

Next, you probably need to place those files under your local web-server and open the HTML like this:

http://[local server host]/ajax.html

instead of opening the file directly from e.g. Windows Explorer:

C:\[path to the file]\ajax.html

For the latter case you'll get an "Access is denied" error.

-- Pavel

Upvotes: 0

helle
helle

Reputation: 11650

well i guess you have to add the example xml (cd_catalog.xml) to your file system. and you definitively have to access the html file on a server (apache i.e.)

Upvotes: 0

Related Questions