Jump to content

Need to Pull XML Data From A Server


XHTMLboy

Recommended Posts

Hello, now I am trying to pull XML data from a server using JavaScript. I was wondering if someone can help me built it as I have no idea what to do. Basically I need to click on a button inside a web browser which will get the XML data. If you guys can make one using html and javascript and upload it I'd be very happy. :) Thanks for looking.

Link to comment
Share on other sites

The XML DOM tutorial teaches you how to open and read XML files with Javascript. Javascript can only read XML files from the current domain, but you can use a PHP proxy to load XML from other domains.

Link to comment
Share on other sites

The file is on computerlabs.co.uk. The link in the code is where the xml data is stored. When I click the button I want it to pull the xml data from that location which is on computerlabs.co.uk

Link to comment
Share on other sites

Try using a relative URL rather than an absolute URL.

xhttp.open("GET","/computerlabs/get_users.php",false);

If that doesn't work, then check the browser's error console. There are actually a few errors in your code: Forgot closing brace:

	else{

At the moment you're not doing anything with this variable:

xmlDoc=xhttp.responseXML;

The action attribute isn't used like this:

<form name="form" action="get_xml()">

You should forget the <form> tag altogether. Add an onclick attribute to the <input> element instead and change its type to button:

<input type="button" onclick="get_xml()" value="Click">

To prevent any problems, you should declare all your variables with the var keyword:

var xhttp;var xmlDoc;

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...