jQuery Tutorial Tutorials - jQuery .ajaxError()

jQuery .ajaxError()

The .ajaxError() method in jQuery is used to register a handler to be callled when Ajax requests complete with an error.

jQuery .ajaxError() syntax

.ajaxError(handler)

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

jQuery .ajaxError() 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/missing.html" );
});

$( document ).ajaxError(function(event, jqxhr, settings, thrownError ) {
    // only handling the URL we request.
    if ( settings.url == "/res/test/ajax/missing.html" ) {
        $( "#msg" ).text( "Triggered ajaxError handler." );
    }
});

Try now

Date:2019-08-30 02:38:59 From:www.Lautturi.com author:Lautturi