Javascript 口译长';启动';IE11开发工具中ajax调用的网络定时

Javascript 口译长';启动';IE11开发工具中ajax调用的网络定时,javascript,ajax,Javascript,Ajax,在看似随机的时间里,我使用的应用程序需要几秒钟来发送ajax调用,而且我很难解释调试器中网络选项卡中的数据 基本上,“启动”需要4到12秒。如果我查看MSDN文档和浏览器本身,它会说:“从最初创建请求到发送请求的时间。” 这是什么意思 是在创建xmlhttp变量和调用对象的send()方法之间的时间吗?这就是我对“从创建到发送”的解释。这意味着问题在ajax请求代码中的某个地方 或者是点击GUI之间的时间,这将调用一系列函数,其中一个将触发ajax调用?这意味着在事件处理程序和ajax函数调

在看似随机的时间里,我使用的应用程序需要几秒钟来发送ajax调用,而且我很难解释调试器中网络选项卡中的数据

基本上,“启动”需要4到12秒。如果我查看MSDN文档和浏览器本身,它会说:“从最初创建请求到发送请求的时间。”

这是什么意思

  • 是在创建xmlhttp变量和调用对象的send()方法之间的时间吗?这就是我对“从创建到发送”的解释。这意味着问题在ajax请求代码中的某个地方

  • 或者是点击GUI之间的时间,这将调用一系列函数,其中一个将触发ajax调用?这意味着在事件处理程序和ajax函数调用之间有很大的延迟

  • function get( path ) {
        var xmlhttp = null,
            domainRequest = false,
            handler,
            queryName,
            result = {};
        if (path.charAt(0) === '/') path = this.host + path;
        // Implicit resource name, get from path.
        if (arguments.length === 2) {
            queryName = path.substring(7).split('/')[1];
            handler = arguments[1];
        }
        // Explicit resource name or alias.
        else if (arguments.length === 3) {
            queryName = arguments[1];
            handler = arguments[2];
        }
        result[queryName] = {
            "value" : null,
            "info" : {
                "filtered" : false,
                "query" : queryName,
                "server" : false,
                "status" : "ERROR",
                "message" : ""                      
            }
        };
        xmlhttp = new XMLHttpRequest();
        xmlhttp.onload = function() {
            var type = (domainRequest) ? 'text/plain' : xmlhttp.getResponseHeader('Content-Type'),
                response = (type === 'text/xml') ? xmlhttp.responseXML : xmlhttp.responseText;
            if (response) result[queryName] = response;
            else result[queryName].info.message = "Malformed data.";
            handler(result);
        };
        xmlhttp.onerror = function() {
            // Failure on the network level.
            if (window.navigator.onLine) result[queryName].info.message = "The requested resource could not be found or the service is down.";
            else result[queryName].info.message = "No network.";
            handler(result);
        };
        xmlhttp.open('GET', path);
        // CORS and IE10-IE11 withCredentials fix: the object state has to be OPEN to set the credentials flag in IE10-IE11
        xmlhttp.withCredentials = true;          
        // IE7-9 domain request premature abort fix.
        // http://cypressnorth.com/programming/internet-explorer-aborting-ajax-requests-fixed/
        xmlhttp.ontimeout = function() {
            result[queryName].info.message = "Network timeout.";
            handler(result);
        };
        xmlhttp.onabort = function() {
            result[queryName].info.message = "Request aborted.";
            handler(result);
        };
        xmlhttp.onprogress = function() {};
        xmlhttp.send();
    }
    
  • 我是否因为发出大量请求而遇到浏览器请求队列限制?如果这可能是一个问题,有没有关于如何检查的提示

  • 还有别的吗

在选项1正确且ajax函数有问题的情况下,我将包含进行ajax调用的当前代码

function get( path ) {
    var xmlhttp = null,
        domainRequest = false,
        handler,
        queryName,
        result = {};
    if (path.charAt(0) === '/') path = this.host + path;
    // Implicit resource name, get from path.
    if (arguments.length === 2) {
        queryName = path.substring(7).split('/')[1];
        handler = arguments[1];
    }
    // Explicit resource name or alias.
    else if (arguments.length === 3) {
        queryName = arguments[1];
        handler = arguments[2];
    }
    result[queryName] = {
        "value" : null,
        "info" : {
            "filtered" : false,
            "query" : queryName,
            "server" : false,
            "status" : "ERROR",
            "message" : ""                      
        }
    };
    xmlhttp = new XMLHttpRequest();
    xmlhttp.onload = function() {
        var type = (domainRequest) ? 'text/plain' : xmlhttp.getResponseHeader('Content-Type'),
            response = (type === 'text/xml') ? xmlhttp.responseXML : xmlhttp.responseText;
        if (response) result[queryName] = response;
        else result[queryName].info.message = "Malformed data.";
        handler(result);
    };
    xmlhttp.onerror = function() {
        // Failure on the network level.
        if (window.navigator.onLine) result[queryName].info.message = "The requested resource could not be found or the service is down.";
        else result[queryName].info.message = "No network.";
        handler(result);
    };
    xmlhttp.open('GET', path);
    // CORS and IE10-IE11 withCredentials fix: the object state has to be OPEN to set the credentials flag in IE10-IE11
    xmlhttp.withCredentials = true;          
    // IE7-9 domain request premature abort fix.
    // http://cypressnorth.com/programming/internet-explorer-aborting-ajax-requests-fixed/
    xmlhttp.ontimeout = function() {
        result[queryName].info.message = "Network timeout.";
        handler(result);
    };
    xmlhttp.onabort = function() {
        result[queryName].info.message = "Request aborted.";
        handler(result);
    };
    xmlhttp.onprogress = function() {};
    xmlhttp.send();
}

“我是否遇到浏览器请求队列限制”
您拨打了多少个电话?有多少其他http请求处于活动状态?@epascarello通常只有4个,在一个承诺中链接在一起。我不认为这是问题所在,因为即使这些请求是唯一的4个,也会发生这种情况,并且在发出40多个请求时并不总是发生这种情况。我只是把它列为我调查过的问题之一,但没有发现任何相关的或可复制的东西。@Shilly如果你最终找到了这一问题的根本原因,那就很高兴知道了。我们正在经历类似的行为。@DylanLindgren很抱歉,但我们没有找到具体的解决方案。到现在为止,我们对mvc结构和node.js后端做了很多更改。ajax调用内部唯一的变化是添加
xhr.navigationbort=false但我实际上再也找不到文档了,为什么我们要添加它:但是,在更改后,我们遇到的问题较少,因此可能是代码的某些部分效率非常低。现在我想起来了:我们做了一件更改,即显式地将所有xhr请求对象保存在数组中,如果最终用户导航到发出该请求的状态之外,则取消它们。因此,另一种选择是,我们的“挂起”请求不再出现在开发工具中,占用了大量资源。
“我是否遇到浏览器请求队列限制”
您拨打了多少电话?有多少其他http请求处于活动状态?@epascarello通常只有4个,在一个承诺中链接在一起。我不认为这是问题所在,因为即使这些请求是唯一的4个,也会发生这种情况,并且在发出40多个请求时并不总是发生这种情况。我只是把它列为我调查过的问题之一,但没有发现任何相关的或可复制的东西。@Shilly如果你最终找到了这一问题的根本原因,那就很高兴知道了。我们正在经历类似的行为。@DylanLindgren很抱歉,但我们没有找到具体的解决方案。到现在为止,我们对mvc结构和node.js后端做了很多更改。ajax调用内部唯一的变化是添加
xhr.navigationbort=false但我实际上再也找不到文档了,为什么我们要添加它:但是,在更改后,我们遇到的问题较少,因此可能是代码的某些部分效率非常低。现在我想起来了:我们做了一件更改,即显式地将所有xhr请求对象保存在数组中,如果最终用户导航到发出该请求的状态之外,则取消它们。因此,另一种选择是,我们有“挂起”的请求,这些请求不再出现在开发工具中,占用资源。