duanchi8836 2016-03-17 16:49
浏览 22

无限滚动不起作用

For my profile_page.php, by default, 10 posts (10 rows from the db) are shown to the user. 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). 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.

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.

Here is 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):

<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.

Here is ajax.php (again, simplified version):

$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) enter image description here

Firefox console.log(data) enter image description here

  • 写回答

1条回答 默认 最新

  • douzi2749 2016-03-17 16:56
    关注

    Check this scroll and try it

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

报告相同问题?

悬赏问题

  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计