Reputation: 85
Is there a way to put a wit image (ie wait.gif) while using XMLHttpRequest?
I have a 'hidden' div called 'loader'. Where do I change the display to block, and back to none?
Here is basically my code:
var xmlhttp;
if (window.XMLHttpRequest){
xmlhttp=new XMLHttpRequest();
}
else {
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
///Do Something with answer
}
}
xmlhttp.open("GET","gtservice01.php?s="+req01,true);
xmlhttp.send();
I am not ready to take the jquery jump yet.
Thx
R
Upvotes: 2
Views: 300
Reputation: 28722
xmlhttp.onreadystatechange=function( ) {
if(xmlhttp.readyState==4){
//set display to none
document.querySelector("div#loader").style.display="none";
if(xmlhttp.status==200){
//Do Something with answer
}
}
}
xmlhttp.open("GET","gtservice01.php? s="+req01,true);
//set display to block
document.querySelector("div#loader").style.display="block";
xmlhttp.send();
Upvotes: 3