jQuery ajaxComplete() Method (original) (raw)

Last Updated : 12 Jul, 2023

The **ajaxComplete() method is used to specify a function to be run when an AJAX request completes.

**Syntax:

$(document).ajaxComplete(function(event, xhr, options))

**Parameter:

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

html `

<script>
    $(document).ready(function () {
        $(document).ajaxComplete(function () {
            alert(" AJAX request completes.");
        });
        $("button").click(function () {
            $("#paragraph").load("demo.txt");
        });
    });
</script>

<style>
    body {
        text-align: center;
    }
</style>

GeeksforGeeks

A computer science portal for geeks

Change Content

`

**demo.txt

"This is GeeksforGeeks.!"

**Output:

jquery-72

**Example 2: This example changes the content of

element, by taking the data from the server. When the AJAX request completes, the page says

AJAX request completes.

html `

GeeksforGeeks

A computer science portal for geeks

Change Content

`

**demo.txt

"This is GeeksforGeeks.!"

**Output:

jquery-73