How to show loader for "Ajax call with async: false"?

Forums jQueryHow to show loader for "Ajax call with async: false"?
Staff asked 2 years ago

I’m facing issue like loader is not showing when Ajax call is with async:false?

Answers (2)

Add Answer
Chand Dakhara Marked As Accepted
Staff answered 1 month ago

Hello, @Riya Patel

You can do one thing to solve this problem. You can use setTimeout method for an ajax call. First show the loader then set the timeout of 1 second for the ajax call.
For example:

$('#loader').show();
setTimeout(function () {

  $.ajax({
    method: "POST",
    url: "",
    dataType: "json",
    async: false,
    data: {},
    success: function (data) {
      
    },
    error: function (data) {
    }
  });
}, 100);

 

This solution is working fine..😀

Thank you @Chand Dakhara

Riya Patel replied 1 month ago
Staff answered 2 months ago

<body onload=”loadingAjax()”>
<div id=”myDiv”>
<span id=”showloader”>Loging…</span>
</div>
</body>

<script>

function loadingAjax() {
$(“#showloader”).show();
$.ajax({
url: “url”,
async: false,
complete: function() {
$(“#showloader”).hide();
}
});
}

</script>

Hope this can help you.

Thank you for your answer
I’ve already tried this but it is not working.

Riya Patel replied 1 month ago

Subscribe

Select Categories