javascript - jQuery: How to identify which XHR handler ajaxComplete() was fired off for -


i have multiple $.get() handlers in javascript. i'd able run specific code when handler has finished request. jquery's documentation, looks following i'm looking for:

$( document ).ajaxcomplete(function() {   $( ".log" ).text( "triggered ajaxcomplete handler." ); }); 

the problem have here is, going triggered every $.get() handler. how can identify 1 going off can take correct steps required update user interface?

you xhr object , settings object argument callback, can use them identify ajax method

$(document).ajaxcomplete(function (event, jqxhr, settings) {     console.log(jqxhr)     $(".log").text("triggered ajaxcomplete handler."); }); 

but if want register callback particular ajax request , have access ajax request's promise object can use .always() callback like

var promise = $.post('/echo/json/', {});//or $.ajax() etc promise.always(function(){     //do }) 

Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -