Skip to content Skip to sidebar Skip to footer

How To Override Jquery Promise Callback

I've created a convenience method that adds a default error handler for my ajax calls: function myAjaxFunction(url, data) { return $.ajax({ url: url, data: dat

Solution 1:

How do I get it to remove the previous error handler from the chain?

You cannot.

or override it?

You could undo what it did (overriding its effects). However, you should better avoid adding the general handler at all - to do that, you will have to change your convenience method. I'd recommend a custom handler as an optional parameter:

function myAjaxFunction(url, data, customHandler) {
    return $.ajax({
        url: url,
        data: data

    }).fail(customHandler || myErrorHandler);
}

Post a Comment for "How To Override Jquery Promise Callback"