2016-05-13 80 views
0

我正在使用以下AJAX将一些帖子内容拉入灯箱。所有的作品都很棒,但速度有点慢。任何人都可以给我一些指针,添加一个加载器图标到下面的代码?AJAX加载图标

谢谢!

  jQuery(document).ready(function ($) { 

       $(".getpostidlink").unbind('click'); 

       $(".getpostidlink").mouseover(function (event) { 
        $(".getpostidlink").unbind('click'); 
        var postlinkid = $(this).data("postid"); 
        var data = { 
         action: 'getpostidhref_action', 
         security: getpostidhref.security, 
         postdata: postlinkid, 
         complete: function() { 
          $(".getpostidlink").unbind('click'); 
         } 
        }; 
        $.post(getpostidhref.ajaxurl, data, function (response) { 
         $(".getpostidlink").colorbox({ 
          inline: true, 
          width: "90%", 
          maxWidth: 800, 
          open: false, 
          onClosed: function() { 
           window.location.reload(); 
          } 
         }) 
         $("div.dynamicloadcontent").replaceWith(response); 
        }); 
       }); 
      }); 
+0

检查该链接http://stackoverflow.com/questions/14859437/how-to-manually-make-the-colorbox-loading-gif-appear ,http://stackoverflow.com/questions/5412263/colorbox-show-simulate-loading-animation-for-inline-content –

回答

2

如果您检查ajax方法的jQuery文档,有几个参数可供您在此处帮助。

具体而言,您可以使用beforeSendcomplete在ajax完成之前和之后显示和隐藏加载图标。

这里看到更多的信息:

http://api.jquery.com/jquery.ajax/