jQuery ajaxComplete() Method

jQuery ajaxComplete() method to be called when Ajax requests complete. Whenever an Ajax request completes jQuery triggers the ajaxComplete event, even if it is not successful.

Syntax

Here is a syntax for ajaxComplete() method

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

Example

ajaxfile.html
<html>
  <body>
    <p>Ajax is use to jQuery to open URL documents with in the documents</p>
    <br />
    <p>AJAX = Asynchronous JavaScript and XML</p>
  </body>
</html>

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

<!DOCTYPE html>
<html>
<head>
  <title>jQuery ajaxComplete() event method</title>
  <script src="jquery-latest.min.js"></script>
  <script>
    $(document).ready(function() {
      $("button").click(function(event){
        $("#msg").load("ajaxfile.html");  
      });
      $(document).ajaxComplete(function(){
        $("#complate").text("Request Complete.");
      });
    });
  </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;">First paragraph start here</div>
</body>
</html>

Run it...   »