Javascript 如果DOM包含改变高度的div,则在scroll上加载更多数据
我有这段AJAX代码Javascript 如果DOM包含改变高度的div,则在scroll上加载更多数据,javascript,php,jquery,ajax,Javascript,Php,Jquery,Ajax,我有这段AJAX代码 $(window).on('scroll', function(e) { if ($(window).scrollTop() >= $(document).height() - $(window).height()) { $.ajax({ type:'GET', url:'includes/fetch_home_posts_2.php',
$(window).on('scroll', function(e) {
if ($(window).scrollTop() >= $(document).height() - $(window).height()) {
$.ajax({
type:'GET',
url:'includes/fetch_home_posts_2.php',
data:{ 'offset':flag, 'limit':5},
success:function(data){
$('#fetched_home_posts').append(data);
flag += 5;
}
});
}
});
当用户加载页面时,他会看到前5篇文章。
这些帖子如下所示:
多亏了这段AJAX代码,他在scroll上加载了更多的帖子(效果很好)
问题是,当用户单击“Comments”按钮时,div会展开,改变其高度,当用户点击页面底部时,不会加载更多的帖子(即使要加载的帖子更多)
这种情况怎么能解决呢?所以我错了。我在不同的
标记中有几个“flag”变量。我刚刚将它们重命名为“post\u flag”
,“comment\u flag”
等,现在它正在工作。所以我错了。我在不同的
标记中有几个“flag”变量。我刚刚将它们重命名为“post\u flag”
,“comment\u flag”
等,现在它正在工作