I have the following ajaxSetup configuration:
$.ajaxSetup({
type: 'GET',
headers: headers,
error: function (data, par1, par2) {
//Error handling code here
}
});
One of the members of my team wanted to handle errors in a different way in his ajax call
$.ajax({
url: url,
}).done(function (result) {
//Success code here
}).fail(function (e) {
//Error handling code here
});
The problem is that the error is getting handled in both sides, error (from ajaxSetup) and fail
To avoid double handling we add an empty Error function, like this
$.ajax({
url: url,
error: function () {},
}).done(function (result) {
//Success code here
}).fail(function (e) {
//Error handling code here
});
But it seems a bit dirty, for my mind one of them should be executed not both, so my question is how should I configure my ajaxSetup in order to avoid this "issue"?
fail(). Overwriting the property, as you are doing, is a clean way to reset the default handler. It should be possible to set it tonullinstead of an empty anonymous function though.