jQuery ajaxStop() Method

jQuery ajaxStop() method to be called at the end when all AJAX requests completed.

When an Ajax request completes, jQuery checks whether there are any pending Ajax requests. If none of requests pending then jQuery triggers the ajaxStop event.

Syntax

Here is a syntax for ajaxStop() method

$(selector).ajaxStop( function() );
Parameter Type Description
function() Function Required. A specifies callback function to be run when all AJAX requests completed.

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 ajaxStop() method call when click on button.

<!DOCTYPE html>
<html>
<head>
  <title>jQuery ajaxStop() event method</title>
  <script src="jquery-latest.min.js"></script>
  <script>
    $(document).ready(function() {
      var count = 0;
      $("button").click(function(event){
        $("#msg").load("ajaxfile.html");  
      });
      $(document).ajaxStart(function(){
        count++;
        $("#start").text("Start Count: " + count );
      });
      $(document).ajaxComplete(function(){
        count++;    
        $("#complete").text("Complete Count: " + count );
      });
      $(document).ajaxStop(function(){
        count++;    
        $("#stop").text("Stop Count: " + count );
      }); 
    });
  </script>
</head>
<body>
  <p id="start">ajaxStart</p>
  <p id="complete">ajaxComplete</p>
  <p id="stop">ajaxStop</p>
  <button>Click here to call ajaxStop() method</button>
  <br /><br />
  <div id="msg" style="background-color:pink;">First paragraph start here</div>
</body>
</html>

Run it...   »