jQuery Tutorial Tutorials - jQuery .ajaxComplete()

jQuery .ajaxComplete()

The .ajaxComplete() method in jQuery is used to register a handler to be callled when Ajax requests complete.

jQuery .ajaxComplete() syntax

.ajaxComplete(handler)

handler is a function to call once the Ajax requests is complete.

jQuery .ajaxComplete() example

example

Show a message when an Ajax request completes.

HTML

<button id="ajaxReq">Ajax Request</button>
<div id="result"></div>
<div id="msg"></div>

jQuery

$( "#ajaxReq" ).click(function() {
    $( "#result" ).load( "/res/test/ajax/1.html" );
});

$( document ).ajaxComplete(function() {
    $( "#msg" ).text( "Triggered ajaxComplete handler." );
});

Try now

example

Show a message "loading" when ajax request processes and hide the message when it completes

$("#ajax").ajaxStart(function(){
    $("#loading").css("display","block");
});
$("#ajax").ajaxComplete(function(){
    $("#loading").css("display","none");
});
Date:2019-08-30 02:37:44 From:www.Lautturi.com author:Lautturi