zoukankan      html  css  js  c++  java
  • alert对ajax阻塞调查(IE, Chrome, FF)

    前阵子做保守工作,对一个js效果进行了改进,由于自己在chrome下测试没问题就丢给同事测试,同事用的是FF,发现不正常,后来又发现这个js在IE10下也不行,不得不调查,结果发现Chrome的alert对ajax是完全阻塞的,但是IE10和FF即使弹出alert,也不会影响正在ajax的访问,也就是不阻塞ajax。

    附上测试代码

    <div id="result"></div>
    
    <script>
        function loadXMLDoc(url) {
            var xmlhttp;
            xmlhttp = null;
            xmlhttp = new XMLHttpRequest();
            xmlhttp.onreadystatechange = function () {
                if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                    if (xmlhttp.responseText == '1') {
                        alert(1);
                        document.getElementById('result').innerHTML='';
                    }else if(xmlhttp.responseText == '2') {
                        document.getElementById('result').innerHTML='123456';
                    }
                }
            };
            xmlhttp.open("GET", url, true);
            xmlhttp.send(null);
        }
    
        loadXMLDoc('http://localhost/echo.php?s=1');//返回1,为了让alert弹出
        loadXMLDoc('http://localhost/echo.php?s=2');//返回2,为了让div#result部分修改值
    </script>

    会发现在ff和ie10下,alert弹出后及时不关闭它也不会阻塞住后面对div#result部分修改的代码的执行

    但chrome下只有点了ok之后才会修改div#result部分

  • 相关阅读:
    Codeforces 632D 暴力
    Codeforces 632C
    nyoj 1070 诡异的电梯 简单dp
    Codeforces 6225B KMP
    Codeforces 631D
    笔记4:多层感知器(自定义模型)
    笔记3:逻辑回归(分批次训练)
    笔记2:张量简介
    笔记1:入门实例
    送快递(贪心+树形结构)
  • 原文地址:https://www.cnblogs.com/tintin1926/p/3533165.html
Copyright © 2011-2022 走看看