javascript - Hide spinner if ajax call time below 1 sec -


I want to hide the spinner for all AJAX calls which takes 1 second for the server to respond.

My current code is

  $ (window) .ready (function () {$ ('# main_wrapper'). CSS ({overflow: 'hidden'}) Append ('& lt; Div class = "splash" style = "position: absolute; top: 0; right: 0; bottom: 0; left: 0; z-index: 99 99; background: # 0096d6;" Gt; & lt; div id = "spinner" style = "position: absolute; width: 44px; height: 44px; top: 50%; margin-top: -22px; left: 50%; margin-left : -22px; & gt; & lt; / div & gt; & lt; / div & gt; ') .appendTo (' # main_wrapper '); startpinner ($); $ (' # main_wrapper ') .JexStart ( Function () {$ ('body'). Attach the ss ({overflow: 'hidden'}) ('
lieutenant; / div & gt; & Lt; / Div & gt; ') .appendTo (' body '); StartSpinner ("# 145A8C"); $ ("Splash") hidden () delay (1000) .show () .. }). AjaxStop (function () {$ ('. Splash') .FadeOut (300); $ ('. Splash') Remove ();}); });

I tried

  $ (". Splash"). Hide (). Delay (1000). Show ();  

But it does not work properly.

Any thoughts?

I had to face the same problem recently, and I solved only by adding spinner, If AJAX requests take more than 1 second. Therefore, your code should look something like this:

  var timer; $ (Document) .on ({ajaxStart: function () {timer & amp; amp; amp; & amp; amp; amp; time; timer; timer = settimeout (function () {start.spinner ("# 145A8C"); $ ( ". Splash").);}, 1000);}, ajaxStop: function () {$ ('. Splash'). FadeOut (300); Remove $ ('. Splash') (); Clear timeout (timer);}}  

Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -