How to check ajax request is completed in jQuery

Created at 05-Mar-2022 , By samar

How to check ajax request is completed in jQuery

Through many examples, we will learn how to resolve the "How to check ajax request is completed in jQuery".

You can check ajax request is completed in jQuery using complete() and always() method. The .always() method replaces the deprecated .complete() method in latest versions of jQuery.
  • Ajax post request with done, fail and always method

    <script> 
    $.ajax({
        url: "/ajax.php",
        method: "POST",
        data:{
            id: 1
        }
    })
    .done(function(resp) {
        console.log(resp);
    })
    .fail(function(xhr, status, error) {
        alert(xhr.statusText);
    })
    .always(function(jqXHR, textStatus) {
        if (textStatus != "success") {
            alert("Error: " + jqXHR.statusText); //error is always called .statusText
        } else {
            alert("Success: " + jqXHR.response); //might not always be named .response
        }
        alert('AJAX call complete');
    }); 
    </script>
    

Back to code snippet queries related jquery

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Buy Me A Coffee

Don't forget to share this article! Help us spread the word by clicking the share button below.

We appreciate your support and are committed to providing you valuable and informative content.

We are thankful for your never ending support.