Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

jQuery | ajaxStop() Method

  • Last Updated : 25 Oct, 2019

The ajaxStop() method is used to specify function to be run when an AJAX requests have completed.
Syntax:

$(document).ajaxStop(function())

Parameter:: It takes only one parameter.

  • function(): It specifies the function to run when the Ajax requests have completed.

The demo.txt file stored on server and it will load after clicking the change content button.
The content of demo.txt are:
This is GFG.

Example-1: This example changes the content of < p > element, by taking the data from server. When the request has completed, the page says AJAX request stopped.




<!DOCTYPE html>
<html>
  
<head>
    <script src=
    </script>
    <script>
        $(document).ready(function() {
            $(document).ajaxStop(function() {
                alert(
                  "AJAX request stopped");
            });
            $("button").click(function() {
                $("#paragraph").load(
                  "demo.txt");
            });
        });
    </script>
    <style>
        body {
            text-align: center;
        }
    </style>
</head>
  
<body>
    <div id="div_content">
        <h1 style="color: green;">
          GeeksforGeeks
      </h1>
        <p id="paragraph"
           style="font-size: 20px;">
          A computer science portal for geeks
        </p>
    </div>
    <button>Change Content</button>
</body>
  
</html>

Output:

  • Before click on the button:
  • After click on the button:

Example-2: This example changes the content of < h1 > element, by taking the data from server. When the request has completed, the page says AJAX request stopped.




<!DOCTYPE html>
<html>
  
<head>
    <script src=
    </script>
    <script>
        $(document).ready(function() {
            $(document).ajaxStop(function() {
                alert(
                  "AJAX request stopped");
            });
            $("button").click(function() {
                $("#paragraph").load(
                  "demo.txt");
            });
        });
    </script>
    <style>
        body {
            text-align: center;
        }
    </style>
</head>
  
<body>
    <div id="div_content">
        <h1 style="color: green;">
          GeeksforGeeks
      </h1>
        <p id="paragraph" 
           style="font-size: 20px;">
      A computer science portal for geeks
        </p>
    </div>
    <button>Change Content</button>
</body>
  
</html>

Output:

  • Before click on the button:
  • After click on the button:




My Personal Notes arrow_drop_up
Recommended Articles
Page :