0

我在一个应用程序中工作,我正在使用以下方法捕获所有 ajax 请求:

$(document).ajaxComplete(function (xhr, status) {
        //...
});

现在,我正在使用MicrosoftMvcAjaxandMicrosoftAjax当 XHR 请求完成时控制台中的一条消息说:XHR finished loading.

xhr当请求完成或 in 的等价ajaxComplete物时,我如何捕捉xhr

4

1 回答 1

0

使用计数器

var _complete = 0, _on = 0;

function incr(){ _on++; }
function comp(){ _complete++; if(_complete==_on) console.log("All the completed")}

// Now use these function wherever you want to make an AJAX Call like

incr();
var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    comp();
    document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","ajax_info.txt",true);
xmlhttp.send();
于 2015-02-16T22:08:32.943 回答