PDA

View Full Version : Display loading icon while script is working


levani
06-08-2009, 09:56 PM
// JavaScript Document
function getXMLHTTP() { //fuction to return the xml http object
var xmlhttp=false;
try{
xmlhttp=new XMLHttpRequest();
}
catch(e) {
try{
xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e){
try{
req = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e1){
xmlhttp=false;
}
}
}

return xmlhttp;
}
function getSubCat(categoryid,selected)
{
var strUrl = "ajax.php?categoryid="+categoryid+"&selcat="+selected+"";
var req = getXMLHTTP();
if(req)
{
req.onreadystatechange = function()
{
if(req.readyState == 4)
{
if(req.status == 200)
{
document.getElementById('divsubcat').innerHTML = req.responseText;
}
else
{
alert("There was a problem while using XMLHTTP \n"+req.statusText);
}
}
}
req.open("GET", strUrl, true);
req.send(null);
}
}
The code above connects two list menus. It opens different list menu according to what is selected in second. But sometimes it takes several seconds to change the list when the selection is changed. How can I display loading icon during this time?

Thanks in advance

levani
06-08-2009, 10:01 PM
Sorry for double posting...

A1ien51
06-09-2009, 02:42 PM
Before you call send show a hidden image on the page. When the response comes back you hide the image.

Eric