Jump to content

Need to Pull XML Data From A Server


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 post
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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...