Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add loading indicator while data is loading

Tags:

jquery

ajax

I would like to display loading indicator while data is loading. below is my current codes:

$.ajax({
     type: "POST",
     url: "URL",
     data: dataString,
     cache: false,
     success: function(html) {
         $("#div").html(html);
     }
});

What should I do?

like image 210
user2861903 Avatar asked Aug 27 '26 18:08

user2861903


2 Answers

use this:

$.ajax({
     type: "POST",
     url: "URL",
     data: dataString,
     cache: false,
     success: function(html) {
         $(selector).html();
         $("#div").html(html);
     },
     beforeSend: function(){
         $(selector).html("your loading image");
     }

});
$(selector).html();
like image 177
Code Lღver Avatar answered Aug 30 '26 09:08

Code Lღver


You may use jquery ajaxStart and ajaxStop utilities for this.

like

$( document ).ajaxStart(function() {
  $( "#loading" ).show();
});
like image 42
Mithun Satheesh Avatar answered Aug 30 '26 11:08

Mithun Satheesh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!