0

私はアプリで作業しており、次を使用してすべての ajax リクエストをキャッチしていました。

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

現在、私は and を使用しMicrosoftMvcAjaxMicrosoftAjaxおり、XHR リクエストが完了すると、コンソールに次のようなメッセージが表示されますXHR finished loading

xhrリクエストが終了したとき、またはajaxCompleteinに相当するものをキャッチするにはどうすればよい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 に答える