English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
When an Ajax request is completed and an error occurs, the ajaxError() method will attach a function to be called. This is an AjaxEvent.
jQuery will trigger the ajaxError event every time an Ajax request is completed and an error occurs. At this time, all handlers registered with the ajaxError() method will be executed.
Note:From jQuery 1.8Since version, this method should only be attached to the document.
$("document").ajaxError(function(event, xhr, options, thrownError))
Display a message when an Ajax request fails:
$("document").ajaxError(function(){ $("#error").text("An error occurred!!!"); });Test to see‹/›
You can get more useful output by using the event, xhr, and options parameters:
$("document").ajaxError(function(event, xhr, options){ $("#error").append("Error requesting page: "); + options.url); $("#error").append(xhr.status); $("#error").append(event.type); });Test to see‹/›
Parameters | Description |
---|---|
function(event, xhr, options, thrownError) | Specify a function to run when the request completes and an error occurs Parameters:
|