4

我正在使用带有评论系统的 ajax 无限滚动。在用户发布新评论之前它工作正常 - 这会破坏无限滚动,“加载更多项目”链接仍然存在,但当您单击它时没有任何反应。

我看过这个问题:Reset / disable infinite scroll after AJAX call

我试图在我的成功方法中实现销毁和绑定,但 loadmoreitems 链接没有响应。用户使用以下代码发表评论后,如何重置无限滚动?

阿贾克斯:

<script>
$(document).ready(function(){
$('#commentform').on('submit',function(e) {

$.ajax({
    url:'ajaxrequest.php',
    data:$(this).serialize(),
    type:'POST',
    dataType: 'HTML',
    success:function(data, response){

ias.destroy(); 

$("#posts").fadeOut(300);       
$('#posts').html(data)
$("#posts").fadeIn(500);
$('html, body').animate({ scrollTop: $('#posts').offset().top - 100 }, 'fast');

ias.bind(); 

 jQuery.ias({
  container: "#posts",
  item: ".post",
  pagination: "#pagination",
  next: ".next a"
});
    },
    error:function(data){
        $("#error").show().fadeOut(5000);
    }
    });

e.preventDefault();
return false;

});
});
</script>
4

1 回答 1

1

当您在加载时初始化滚动时,请确保您已将其存储在名为 ias 的变量中。像这样的东西

var ias = jQuery.ias({
  container: "#posts",
  item: ".post",
  pagination: "#pagination",
  next: ".next a"
});

并且在成功方法中只调用ias.destroy();andias.bind();方法,就像您之前所做的那样。

删除在您的代码中再次完成的初始化,即

jQuery.ias({
  container: "#posts",
  item: ".post",
  pagination: "#pagination",
  next: ".next a"
});
于 2014-11-25T12:07:27.600 回答