Jump to content

Simple AJAX question


Recommended Posts

ok well ive been looking up the AJAX tutorials at w3schools. and I was wondering how I can make the httprequest code display a loading message while the requested content is being retrieved. heres the code:

<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>

how can I make that script show a loading message on the button click while the server is getting the wanted xml data.

Link to post
Share on other sites

even though you've said you've gotten it to work, might i say look up MooTools' ajax component. Takes a lot of issue out of making an Ajax request, includes a bunch of handy events as well( onComplete, for example fires when the status is equal to 4, onRequest fires when the ajax request begins, onFailure happens when the request errors for some reason etc etc). Just a thought.

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...