jQuery ajaxError() Methode

❮ jQuery AJAX-Methoden

Beispiel

Löst ein Warnfeld aus, wenn eine AJAX-Anforderung fehlschlägt:

$(document).ajaxError(function(){
  alert("An error occurred!");
});

Definition und Verwendung

Die Methode ajaxError() gibt eine Funktion an, die ausgeführt werden soll, wenn eine AJAX-Anforderung fehlschlägt.

Hinweis: Ab jQuery Version 1.8 sollte diese Methode nur noch an document angehängt werden.


Syntax

$(document).ajaxError(function(event,xhr,options,exc))

Parameter Description
function(event,xhr,options,exc) Required. Specifies the function to run if the request fails
Additional parameters:
  • event - contains the event object
  • xhr - contains the XMLHttpRequest object
  • options - contains the options used in the AJAX request
  • exc - contains the JavaScript exception, if one occurred

Probieren Sie es selbst aus - Beispiele


So verwenden Sie den Optionsparameter, um eine nützlichere Fehlermeldung zu erhalten.


❮ jQuery AJAX-Methoden