首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >没有onreadystatechange的ajax请求

没有onreadystatechange的ajax请求
EN

Stack Overflow用户
提问于 2011-08-12 20:27:08
回答 1查看 277关注 0票数 0

函数loadXMLDocLogout() {

代码语言:javascript
复制
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);

}

尽管对xmlhttpLogOut.onreadystatechange=function()行进行了注释,但上面的代码工作得很好!

提前感谢您的帮助。

EN

回答 1

Stack Overflow用户

发布于 2011-08-12 20:56:40

上面的代码运行得很好

当然,它是有效的javascript代码。

if (xmlhttpLogOut.readyState==4 && xmlhttpLogOut.status==200)将失败,因此

代码语言:javascript
复制
else
        document.getElementById("loadingDiv").style.display="block";

将被执行。

但是,它是否会产生与未注释的xmlhttpLogOut.onreadystatechange=function()相同的结果?也就是说,元素被隐藏了(如果它已经可见)?我对此表示怀疑。

你试过所有可能的测试用例了吗?

(首先,在发送loadingDiv请求之前是否隐藏了Ajax div?)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7040038

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档