jQuery ajaxError() Method

jQuery ajaxError() method to be called when AJAX request completes with an error. Whenever an Ajax request completes with an error jQuery triggers the ajaxError event.

Syntax

Here is a syntax for ajaxError() method

$(selector).ajaxError( function(event, jqXHR, options, thrownError) );
Parameter Type Description
function(event, jqXHR, options) Function Required. A specifies callback function to be run when the request an error.
Additional parameters
  • event - contains standard event object
  • jqXHR - contains the XMLHttpRequest object
  • options - contains plain object used in the AJAX request
  • thrownError - contains the JavaScript exception to throw an error

Example

Here, in this example ajaxError() method call when click on button.

<!DOCTYPE html>
<html>
<head>
  <title>jQuery ajaxError() event method</title>
  <script src="jquery-latest.min.js"></script>
  <script>
    $(document).ready(function() {
      $("button").click(function(event){
        $("#msg").load("filenotfound.html");  
      });
      $(document).ajaxError(function(){
        $("#complate").text("File not found! Probably removed.");
      });
    });
  </script>
</head>
<body>
  <p id="complate">Response</p>
  <button>Click here to call ajaxComplete() method</button>
  <br /><br />
  <div id="msg" style="background-color:pink;">New contains update here</div>
</body>
</html>

Run it...   »