javascript - Preload image doesn't always appear -
i have created simple ajax request:
var params = "postdata=" + mydata; if (window.xmlhttprequest) { xmlhttp = new xmlhttprequest(); } else { xmlhttp = new activexobject("microsoft.xmlhttp"); } xmlhttp.onreadystatechange = function () { if (xmlhttp.readystate == 4 && xmlhttp.status == 200) { document.getelementbyid("data").innerhtml = xmlhttp.responsetext; } } xmlhttp.open("post", "data.php", true); xmlhttp.setrequestheader("content-type", "application/x-www-form-urlencoded"); xmlhttp.setrequestheader("content-length", params.length); xmlhttp.setrequestheader("connection", "close"); xmlhttp.send(params);
and html code:
<div id="data"> <img src="/images/preload.gif" /> <b style="color:#9ca6dc;font-size:12px;">wait</b> </div>
the problem preload.gif , "wait" text appears , not always.
why ? how can resolve ?
the explanation ajax request works see content (as alessandro pezzato said). if don't see readystate of xmlhttp request had change.
or have other javascript runs asynchronously , changes on same content.
Comments
Post a Comment