导航栏: 首页 评论列表

浏览器bug导致页面同时弹出多个alert

默认分类 2012-03-23 00:36:46

浏览器bug导致页面同时弹出多个alert

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  2. <html xmlns="http://www.w3.org/1999/xhtml">  
  3.   
  4. <head>  
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
  6. <title>http</title>  
  7. <script type="text/javascript">  
  8. <!--  
  9. function ajax(){  
  10.     var xmlhttp;  
  11.     if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari  
  12.         xmlhttp=new XMLHttpRequest();  
  13.     }  
  14.     else{// code for IE6, IE5  
  15.         xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");  
  16.     }  
  17.     if (xmlhttp!=null){  
  18.         xmlhttp.open("GET","http://127.0.0.1:3000/sleep/t?t=3",true);  
  19.         xmlhttp.setRequestHeader("request_type","ajax");  
  20.         xmlhttp.onreadystatechange=function(){  
  21.             if (xmlhttp.readyState==4 && xmlhttp.status==200){  
  22.                 alert('two');  
  23.                 //document.getElementById("myDiv").innerHTML=xmlhttp.responseText;  
  24.                   
  25.             }  
  26.         };  
  27.         xmlhttp.send();  
  28.           
  29.         //document.getElementById("myDiv").innerHTML=xmlhttp.responseText;  
  30.     }  
  31.     else  
  32.     {  
  33.         alert("Your browser does not support XMLHTTP.");  
  34.     }  
  35.     alert('one');  
  36. }  
  37. //-->  
  38. </script>  
  39. </head>  
  40.   
  41. <body>  
  42. <button onclick="ajax()">button</button>  
  43. <div id="myDiv">myDiv</div>  
  44. </body>  
  45.   
  46. </html>  

如果将ajax提出来作为另外一个独立函数,并适当加大延迟时间,会发现有只能弹出一个,通过服务器端日志可以看到浏览器会在js执行的时候发送http请求


>> 留言评论