Having a little trouble getting my "pre-loader" to show properly... I would assume, what this script would do is that once xmlhttp is invoked, JS would make a div with an ID called 'preload' and it will persist until we get a 400 response from the server, and then destroy the div.
As a note, I am using an animated .gif as a background for the div that is set in an external CSS. Do I need to define the background within the javascript?
Thanks!
Ryan
<script type="text/javascript">
function showProducts(str)
{
if (str=="")
{
document.getElementById("products").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()
{
var body = document.getElementById('main');
var ajaxLoader = document.createElement('div');
ajaxLoader.setAttribute('id', 'preload')
body.appendChild(ajaxLoader);
if (xmlhttp.readyState==4 && xmlhttp.status==200)
var ajaxLoader = document.getElementById('preload');
document.getElementById('main').removeChild(ajaxLoader);
{
document.getElementById("products").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("POST","return.php",true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send("prod_list="+str);
}