Home >>jQuery Tutorial >jQuery ajaxError() Method
jQuery ajaxError() method in jQuery is used to specifies a function to be run when an AJAX request fails.
Syntax:$(document).ajaxError(function(event,xhr,options,exc))
Parameter | Description |
---|---|
function(event,xhr,options,exc) | It is a Required parameter and is used to specifies the function to run if the request fails. Additional parameters:
|
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(document).ajaxError(function(){
alert("Occured an Error!");
});
$(".btn1").click(function(){
$(".div1").load("wrongfile.txt");
});
});
</script>
</head>
<body>
<div class="div1"><h2>Change this text</h2></div>
<button class="btn1">Click me to Change Content</button>
</body>
</html>