开发者

Preload using AJAX

I am trying to preload the entire website with this script:

   <script>
   $(function() {
   $('#body').addClass("none");
    $('#load').ajaxStart(functi开发者_如何学运维on() {
    $(this).show();
  }).ajaxStop(function() {
    $(this).hide();
   });
  $('#body').removeClass("none");
 });
 </script>

My body has a class "none" which is basically a display:none. The #load is my obvious loading div. It seems like there is an issue it actually running because #load shows the entire time, doesn't actually get rid of itself when its done loading.

Any ideas?


I tested your code and it worked without problems.

ajaxStop only gets called when all ajax requests have returned or been cancelled. One of your requests must therefore be hanging. Another possibility is that the request threw an exception (cross domain for example - see here).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜