0

I'm working in an app and I was catching all the ajax request using:

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

Now, I'm using MicrosoftMvcAjax and MicrosoftAjax and when a XHR request finished a message in the console says: XHR finished loading.

How I can catch when a xhr request finish or what is the equivalent for ajaxComplete in xhr?

Benjamin RD
  • 11,516
  • 14
  • 87
  • 157

1 Answers1

0

Use a counters

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();
void
  • 36,090
  • 8
  • 62
  • 107