[英]reset infinite scroll with ajax content
我正在使用帶注釋系統的ajax無限滾動。 它工作正常,直到用戶發布新評論 - 這打破了無限滾動,“加載更多項目”鏈接仍然存在但單擊它時沒有任何反應。
我見過這個問題: 在AJAX調用后重置/禁用無限滾動
我試圖實現destroy並綁定到我的成功方法,但loadmoreitems鏈接沒有響應。 用戶使用下面的代碼發布評論后,如何重置無限滾動?
AJAX:
<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>
初始化加載滾動時,請確保已將其存儲在名為ias的變量中。 像這樣的東西
var ias = jQuery.ias({
container: "#posts",
item: ".post",
pagination: "#pagination",
next: ".next a"
});
並且在成功方法中只調用ias.destroy();
和ias.bind();
你以前做過的方法。
刪除代碼中再次執行的初始化,即
jQuery.ias({
container: "#posts",
item: ".post",
pagination: "#pagination",
next: ".next a"
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.