XHTMLboy Posted January 26, 2013 Share Posted January 26, 2013 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 More sharing options...
Ingolme Posted January 26, 2013 Share Posted January 26, 2013 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 More sharing options...
XHTMLboy Posted January 26, 2013 Author Share Posted January 26, 2013 This is what I've mannaged to do but it's not working. :/ Link to comment Share on other sites More sharing options...
Ingolme Posted January 26, 2013 Share Posted January 26, 2013 Like I said, you can only load files that are on your same domain. Unless this file is on computerlabs.co.uk it's not going to work. Link to comment Share on other sites More sharing options...
XHTMLboy Posted January 26, 2013 Author Share Posted January 26, 2013 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 More sharing options...
Ingolme Posted January 26, 2013 Share Posted January 26, 2013 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now