Tumblr like button not working after ajax load

你。 提交于 2019-12-25 02:09:25

问题


I am using pjax and masonry in my tumblr theme. I just figured out how to get masonry to work after clicking a pjax'd link, but now the problem is that the like button is not working anymore. Here is my code so far:

html:

<article class="entry" id="{PostID}">

</article>

jquery:

$(document).ajaxComplete(function(){
   $('#content').imagesLoaded(function(){
      $('#content').masonry('reloadItems').masonry();
   });

   var $newPosts   = $(data).find('.entry');
   var $newPostIDs = $newPosts.map(function () {
     return this.id;
   }).get();

   Tumblr.LikeButton.get_status_by_post_ids($newPostIDs);
});

回答1:


I believe you need to use pjax:success. This should give you the data object.

$(document).on('pjax:success', function( event, data, status, xhr, options ) {

 $('#content').imagesLoaded(function(){
    $('#content').masonry('reloadItems').masonry();
 });

 var $newPosts   = $(data).find('.entry');
 var $newPostIDs = $newPosts.map(function () {
   return this.id;
 }).get();

 Tumblr.LikeButton.get_status_by_post_ids($newPostIDs);

});

Source: https://github.com/defunkt/jquery-pjax#events



来源:https://stackoverflow.com/questions/30120195/tumblr-like-button-not-working-after-ajax-load

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!