简体   繁体   English

无限滚动不起作用

[英]Infinity Scroll not working

For my profile_page.php , by default, 10 posts (10 rows from the db) are shown to the user. 对于我的profile_page.php ,默认情况下,向用户显示10个帖子(数据库中有10行)。 If the user has more than 10 posts, and scrolls to the bottom of the page, the div should expand to show the remaining posts (10 maximum). 如果用户有10个以上的帖子,并滚动到页面底部,则div应该展开以显示剩余的帖子(最多10个)。 So if a user has 13 posts in total, 10 are shown by default, and then when a user scrolls to the bottom, the remaining three will show. 因此,如果用户总共有13个帖子,则默认显示10个帖子,然后当用户滚动到底部时,将显示其余三个帖子。

That's the idea, but unfortunately, my scroll just is not working. 那是个主意,但是不幸的是,我的滚动条无法正常工作。 The page realizes it has reached the bottom of the page and performs the alert("bottom )` but does not load more posts. 该页面意识到它已到达页面底部并执行alert("bottom )`,但未加载更多帖子。

Here is infinity_scroll.js 这是infinity_scroll.js

$(document).ready(function(){
    var load = 0;   
    var postLen = $('.userposts_panel').find('.message_wrapper').length;
    $(window).scroll(function(){
        if($(window).scrollTop() == $(document).height() - $(window).height()){
            // start AJAX
            if(postLen >= 10){
                load++;
                $.post("inc/ajax.php", {load:load},function (data){
                $(".userposts_panel").append(data); //  class
                        alert ("bottom");
                });
            } // if closed
        } // if closed
        });
    });

The structure of my HTML in which the posts are displayed (simplified version): 显示帖子的HTML结构(简化版):

<div class="userposts_panel">
   // below is the div in which each post is displayed
  <?php echo "<div class='message_wrapper'> </div> ?>
</div>

Seeing as the alert() works, I am beginning to think there is an issue with my ajax.php - but I just cannot find any problems. 看到alert()起作用了,我开始认为我的ajax.php存在问题-但我只是找不到任何问题。

Here is ajax.php (again, simplified version): 这是ajax.php(再次是简化版):

$load = htmlentities(strip_tags($_POST['load']))*10;
$query = mysqli_query ($connect, "SELECT * FROM user_thoughts WHERE added_by='$user' ORDER BY id DESC LIMIT ".$load.",10");

while ($row = mysqli_fetch_assoc($query)) {
    $thought_id      = $row['id'];
    $message_content = $row['message'];
    $date_of_msg     = $row['post_details'];
    $thoughts_by     = $row['added_by'];
    $attachent       = $row['attachment'];

    echo "<div class='message_wrapper'>
      // this is where I will depict all info such as author of post etc.
    </div>";
}
?>

Is anyone able to identify why more data is not being loaded when I reach the bottom of my page? 有谁能够确定我到达页面底部时为什么不加载更多数据的原因?

Edit : 编辑

Chrome console.log(data) Chrome console.log(数据) 在此处输入图片说明

Firefox console.log(data) Firefox console.log(数据) 在此处输入图片说明

Check this scroll and try it 检查此滚动并尝试

$(window).scroll(function() {
   if($(window).scrollTop() + $(window).height() == $(document).height()) {
       alert("bottom!");
   }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM