Jump to content

XML HttpRequest


georgedw

Recommended Posts

I am interested in learning XML I went through the tutorial and thought it was very good. I copied the code from the "Try it yourself" this is the code I copied:<?xml version="1.0" encoding="ISO-8859-1"?><!-- Edited by XMLSpy® --><note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body></note>and this:<html><head><script type="text/javascript">var xmlhttp;function loadXMLDoc(url){xmlhttp=null;if (window.XMLHttpRequest) {// code for IE7, Firefox, Opera, etc. xmlhttp=new XMLHttpRequest(); }else if (window.ActiveXObject) {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }if (xmlhttp!=null) { xmlhttp.onreadystatechange=state_Change; xmlhttp.open("GET",url,true); xmlhttp.send(null); }else { alert("Your browser does not support XMLHTTP."); }}function state_Change(){if (xmlhttp.readyState==4) {// 4 = "loaded" if (xmlhttp.status==200) {// 200 = "OK" document.getElementById('A1').innerHTML=xmlhttp.status; document.getElementById('A2').innerHTML=xmlhttp.statusText; document.getElementById('A3').innerHTML=xmlhttp.responseText; } else { alert("Problem retrieving XML data:" + xmlhttp.statusText); } }}</script></head><body><h2>Using the HttpRequest Object</h2><p><b>Status:</b><span id="A1"></span></p><p><b>Status text:</b><span id="A2"></span></p><p><b>Response:</b><br /><span id="A3"></span></p><button onclick="loadXMLDoc('note.xml')">Get XML</button></body></html>When I run the html file IE7 does nothing but show the error on page icon in the lower left, Safari Opera and Navigator do not display the "OK"If I change the line: if (xmlhttp.status==200)to if (xmlhttp.status!=200)it will at least run on IE7 although it obviously does not show "OK" so the question is what am I doing wrong here?

Link to comment
Share on other sites

If you are running this from your filesystem:

file:///C:/Documents and Settings/Administrator/Desktop/note.xml

Rather than a web server:

http://localhost/note.xml

Then the response status will always be null because there isn't a web server that can provide an actual HTTP Response.

Link to comment
Share on other sites

  • 2 weeks later...

The bruise on my forehead from where I slapped myself saying I knew that has mostly healed, the bumps from beating my head on the wall trying to make localhost node work are still pretty tender though, I finally got it all working thanks so much for the help, stand by for more questions after I find a padded helmet :)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...