Home >Web Front-end >JS Tutorial >How to use the ajaxError() method in jquery

How to use the ajaxError() method in jquery

王林
王林Original
2020-11-25 10:01:382255browse

The usage of the ajaxError() method in jquery is: [$(document).ajaxError(function(event,xhr,options,exc))]. The ajaxError method specifies the function to be run when the ajax request fails.

How to use the ajaxError() method in jquery

The operating environment of this tutorial: Windows 10 system, jquery version 1.10.2. This method is suitable for all brands of computers.

(Related video tutorial: javascript video tutorial)

Introduction:

ajaxError() method specifies the function to be run when the AJAX request fails .

Note: As of jQuery version 1.8, this method is only appended to the document.

Syntax:

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

Parameters:

function(event,xhr,options,exc) Required. Specifies a function to run when a request fails.

Extra parameters:

event - Contains the event object

xhr - Contains the XMLHttpRequest object

options - Contains the options used in the AJAX request

exc - Contains JavaScript exception

Example:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
	$(document).ajaxError(function(){
		alert("一个错误发生!");
	});
	$("button").click(function(){
		$("div").load("wrongfile.txt");
	});
});
</script>
</head>
<body>

<div><h2>使用 AJAX 修改文本</h2></div>
<button>修改内容</button>

</body>
</html>

Related recommendations: js tutorial

The above is the detailed content of How to use the ajaxError() method in jquery. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn