[英]what is the equivalent for ajaxComplete if I use a xhr request?
我在一个应用程序中工作,我正在使用以下方法捕获所有ajax请求:
$(document).ajaxComplete(function (xhr, status) {
//...
});
现在,我正在使用MicrosoftMvcAjax
和MicrosoftAjax
,当XHR请求在控制台中完成消息时说: XHR finished loading
。
我如何能赶上当xhr
请求完成或者什么是等效的ajaxComplete
在xhr
?
使用计数器
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.