开发者

ajax request with no onreadystatechange

开发者 https://www.devze.com 2023-03-27 21:42 出处:网络
function loadXMLDocLogout() { var xmlhttpLogOut; xmlhttpLogOut=new XMLHttpRequest(); //xmlhttpLogOut.onreadystatechange=function()

function loadXMLDocLogout() {

var xmlhttpLogOut;   
 xmlhttpLogOut=new XMLHttpRequest();
  //xmlhttpLogOut.onreadystatechange=function()
  {
     if (xmlhttpLogOut.readyState==4 && xmlhttpLogOut.status==200)
     {
         document.getElementById("loadingDiv"开发者_开发知识库).style.display="none";

     }
     else
        document.getElementById("loadingDiv").style.display="block";
  }
 xmlhttpLogOut.open("GET","http://www.mysite.me/logout.php?LogOut=1",false);    
xmlhttpLogOut.setRequestHeader("Content-type","application/x-www-form-urlencoded"); 
xmlhttpLogOut.send(null);

}

The above code works perfectly despite of line xmlhttpLogOut.onreadystatechange=function() being commented!

Thanks for help in advance.


The above code works perfectly

Of course it will, it is valid javascript code.

The if (xmlhttpLogOut.readyState==4 && xmlhttpLogOut.status==200) will fail and so

else
        document.getElementById("loadingDiv").style.display="block";

will be executed.

But does it produce the same result as the xmlhttpLogOut.onreadystatechange=function() not being commented? That is the element getting hidden (if it is already visible)? I doubt.

Did you try all possible test cases?

(To begin with, was the loadingDiv div hidden before the Ajax request was sent?)

0

精彩评论

暂无评论...
验证码 换一张
取 消