Reputation:
I am making an ajax call with the following script:
window.onload = function() {
if (!session) {
layoutType = document.documentElement.clientWidth;
var xmlhttp;
if (window.XMLHttpRequest)
xmlhttp=new XMLHttpRequest();
}
else
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
window.location.reload();
}
}
xmlhttp.open("POST","core/session.php?bW=" + bW,true);
xmlhttp.send();
}
}
I want to insert a loading image and some text while the pahe loads. How ca I do that?
I want to insert the following image link and text:
<img src="cdn/images/ajax-loader.gif" />
<h3>Please wait while we load</h3>
Please help.
Upvotes: 1
Views: 8318
Reputation: 13569
you can add an image to the loading are when ajax loads it will basically overwrite your image the ajax loader
<script>
var DisplayIMge = document.getElementById("ajaxdiv");
DisplayIMge.innerHTML = "<img src='cdn/images/ajax-loader.gif' /><h3>Please wait while we load</h3>"
</script>
for instance here is the ajax based on the one you are using
<html>
<head>
<script type="text/javascript">
function showHint(str)
{
if (str.length==0)
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("POST","core/session.php?bW=" + bW,,true);
xmlhttp.send();
}
</script>
</head>
<body>
<p><b>Start typing a name in the input field below:</b></p>
<form>
First name: <input type="text" onkeyup="showHint(this.value)" size="20" />
</form>
<p><div id="ajaxdiv"><div></p>
</body>
</html>
Upvotes: 1