浏览器bug导致页面同时弹出多个alert
默认分类 2012-03-23 00:36:46
浏览器bug导致页面同时弹出多个alert
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
-
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>http</title>
- <script type="text/javascript">
- <!--
- function ajax(){
- var xmlhttp;
- if (window.XMLHttpRequest){
- xmlhttp=new XMLHttpRequest();
- }
- else{
- xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
- }
- if (xmlhttp!=null){
- xmlhttp.open("GET","http://127.0.0.1:3000/sleep/t?t=3",true);
- xmlhttp.setRequestHeader("request_type","ajax");
- xmlhttp.onreadystatechange=function(){
- if (xmlhttp.readyState==4 && xmlhttp.status==200){
- alert('two');
-
-
- }
- };
- xmlhttp.send();
-
-
- }
- else
- {
- alert("Your browser does not support XMLHTTP.");
- }
- alert('one');
- }
-
- </script>
- </head>
-
- <body>
- <button onclick="ajax()">button</button>
- <div id="myDiv">myDiv</div>
- </body>
-
- </html>
如果将ajax提出来作为另外一个独立函数,并适当加大延迟时间,会发现有只能弹出一个,通过服务器端日志可以看到浏览器会在js执行的时候发送http请求
>>
留言评论