Ho un gestore globale ajax errore, qui:JQuery Ajax - Come fermare gestore errori globale dinamicamente
function SetAjaxErrorHandler() {
$(document).ajaxError(function (event: JQueryEventObject, jqXHR: JQueryXHR, ajaxSettings: JQueryAjaxSettings, thrownError: string) {
console.log("in error");
// Call error API to log
var url1 = appSettings["errorLogApiUrl"];
$.ajax({
type: "POST",
url: url1 + "s",
data: jqXHR.responseText,
contentType: "application/json; charset=utf-8",
error: (jqXhr) => {
// I dont want the global error handler to be triggered here!
}
});
});
}
Come si può vedere, su un evento si verifica un errore chiamando uno dei l'altro ajax chiama la pagina, sto provando a fare un'altra chiamata API per registrarlo sul server. Tuttavia, se la chiamata per registrare l'errore fallisce, vengo catturato in un ciclo ricorsivo. Quindi la mia domanda è, nella mia chiamata ajax nel metodo ajaxError(), c'è un modo per impedire che il gestore di errori globale venga attivato?
tl; dr esiste un modo per utilizzare un gestore di errori ajax globale per alcune chiamate ajax ma sopprimerlo per altri?