Tags
Asked 2 years ago
24 Jun 2021
Views 265
Gino

Gino posted

Execute function after Ajax call is complete

Execute function after Ajax call is complete
debugger

debugger
answered Apr 28 '23 00:00

To execute a function after an Ajax call is complete, you can use the .done() method in jQuery. This method is called when the Ajax call has completed successfully, regardless of whether the call succeeded or failed. Here's an example code snippet that shows how to use .done() to execute a function after an Ajax call:

$.ajax({
    url: 'example.php',
    type: 'POST',
    data: {
        param1: 'value1',
        param2: 'value2'
    },
    success: function(response) {
        console.log(response);
    }
}).done(function() {
    console.log("Ajax call completed successfully.");
    // Execute your function here
}).fail(function() {
    console.log("Ajax call failed.");
});

In the above code, we use the .ajax() method to make an Ajax call to example.php. The data parameter specifies the data to be sent to the server, and the success callback function is called when the call is completed successfully. We then use .done() to specify the function to be executed after the call is complete. If the call fails, the .fail() method is called instead.

You can replace the console.log() statements with your own code to execute the desired function after the Ajax call is complete
Post Answer