繁体   English   中英

如果我使用xhr请求,ajaxComplete的等价物是什么?

[英]what is the equivalent for ajaxComplete if I use a xhr request?

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

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

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

我如何能赶上当xhr请求完成或者什么是等效的ajaxCompletexhr

使用计数器

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();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM