Latest web development tutorials

jQuery ajaxError () method

jQuery AJAX Methods jQuery AJAX Methods

Examples

When AJAX request fails, triggering an alert box:

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

try it"

Definition and Usage

ajaxError () method specifies AJAX request functions to run on failure.

Note: Since jQuery version 1.8 onwards, this method is only attached to the document.


grammar

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

参数 描述
function(event,xhr,options,exc) 必需。规定当请求失败时运行的函数。
额外的参数:
  • event - 包含 event 对象
  • xhr - 包含 XMLHttpRequest 对象
  • options - 包含 AJAX 请求中使用的选项
  • exc - 包含 JavaScript exception


Examples

More examples

Use xhr parameters and options
How to use the options parameter to get a more useful error message.


jQuery AJAX Methods jQuery AJAX Methods