I am new to AJAX and am trying to write my first AJAX program. I am trying to reach out and connect with a server. I "should" be getting some XML data sent back to me but my responseXML remains null. Below is the code I am using and I will also print out what I am hoping to get back. I am able to create the XMLHttpRequest and my readyState does reach 4. My status is 0 but I expected that.
The code (and I have included some document.writes just to help me debug) is:
When I put the "http://localhost:8080/vlrestapi/v1.0/system" into a browser, this is what I get back and what I hope to pull back with my AJAX program but it is not happening:Code:<html> <head> <script type="text/javascript"> function loadXMLDoc() { document.write(" In function"); var xmlhttp; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); document.write(" created request "); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4) { document.write(xmlhttp.responseText); } } xmlhttp.open("GET","http://localhost:8080/vlrestapi/v1.0/system",true); xmlhttp.send(); } </script> </head> <body> <h2>AJAX</h2> <button type="button" onclick="loadXMLDoc()">Request data</button> </body> </html>
Any help anyone could give me would be greatly appreciated.Code:<?xml version="1.0" encoding="UTF-8" ?> - <VLResponse> <content class="string">VisuaLinks REST API | Host: nb-lhunt/192.168.183.1 | Time: Wed Feb 09 14:38:56 EST 2011</content> </VLResponse>
Thank you


Reply With Quote

Bookmarks