I would like to know how to delay an ajax request so I can see where the loading image displays. Thing is, with localhost, there is no delay in getting the information. There is no download time, so the loading image does not show at all.
Is there a way I can make it show? Here is my onstatechange function that is called when the ajax state changes.
Code: Select all
function stateChanged()
{
if (xmlhttp.readyState==1){}
if (xmlhttp.readyState==2)
{
document.getElementById("loading").style.display = "";
document.getElementById("contents").style.display = "none";
}
if (xmlhttp.readyState==3)
{
document.getElementById("loading").style.display = "";
document.getElementById("contents").style.display = "none";
}
if (xmlhttp.readyState==4)
{
document.getElementById("loading").style.display = "none";
document.getElementById("contents").style.display = "";
document.getElementById("contents").innerHTML=xmlhttp.responseText;
}
}