Javascript examples for jQuery Method and Property:ajaxError
The ajaxError() method sets a function to run when an AJAX request fails.
Parameter | Description |
---|---|
function(event,xhr,options,exc) | Required. |
Additional parameters:
The following code shows how to Trigger an alert box when an AJAX request fails:
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $(document).ajaxError(function(){ console.log("An error occured!"); });/*from w w w.j a va 2 s . c o m*/ $("button").click(function(){ $("div").load("wrongfile.txt"); }); }); </script> </head> <body> <div><h2>Let AJAX change this text</h2></div> <button>Change Content</button> </body> </html>