Odin Thunder
Odin Thunder

Reputation: 3547

How to resend a failed Ajax request globally?

I have a many Ajax request in my project and have a global Ajax Error Handler.

$( document ).ajaxError( function( event, jqxhr, settings) {

    if (// some condition) {
        // resend current Ajax Request
    }

});

How can I detect in which Ajax Request I catch an error and resend it ? I try to find "resend" solutions but do not find for global case. I appreciate any help :)

Upvotes: 0

Views: 144

Answers (1)

Odin Thunder
Odin Thunder

Reputation: 3547

The answer was even simpler than I expected:

$( document ).ajaxError( function( event, jqxhr, settings) {

    if (// some condition) {
        $.ajax(settings);
    }

});

The third parameter is a current Request

Upvotes: 1

Related Questions