简单的方法
最简单的方法是使用
.ajaxStop()事件处理程序:
$(document).ajaxStop(function() { // place pre to be executed on completion of last outstanding ajax call here});艰难的道路
您还可以手动检测是否有任何ajax调用仍处于活动状态:
创建一个包含活动Ajax连接数的变量:
var activeAjaxConnections = 0;
在打开新的Ajax连接之前,递增该变量
$.ajax({ beforeSend: function(xhr) { activeAjaxConnections++; }, url (...)在
success部分检查,如果该变量等于零(如果是的话,最后的连接已完成)
success: function(html){ activeAjaxConnections--; $('#result_'+rowNum).empty().append(html); $('#coda_'+rowNum).removeClass("loading"); $('#coda_'+rowNum).addClass("loader"); if (0 == activeAjaxConnections) { // this was the last Ajax connection, do the thing }},error: function(xhr, errDesc, exception) { activeAjaxConnections--; if (0 == activeAjaxConnections) { // this was the last Ajax connection, do the thing }}如您所见,我还添加了检查返回错误的信息



