惰性页面滚动不起作用,无法找出代码中的问题

yruzcnhs  于 2021-06-19  发布在  Mysql
关注(0)|答案(1)|浏览(289)
<script>

   $(document).ready(function(){
     $.ajax({
       type:"GET",
       url:"fetch_home.php",
       data:{
         'offset':0,
         'limit':1
       },
       success:function(data){
         $('body').append(data);
       }
     });

   $(window).scroll(function(){
     if($(window).scrollTop() >= $(document).height() - $(window).height()){
       alert('at bottom'); 
       // i will place rest of the code here .
     }
   });

   });
      </script>

下面是与ajax链接的php部分-

<?php

if(isset($_POST["limit"],$_POST["start"])){
$con = mysqli_connect('localhost','root','','user_data') or 
  die(mysqli_error());

$query = "SELECT * FROM `challenges` ORDER BY `id` DESC LIMIT {$limit} 
OFFSET {$offset}";

$result = mysqli_query($con,$query);
 while($row = mysqli_fetch_assoc($result))
  {
          echo '<p>'.$row["challenger_name"].'</p>';
   }
   mysqli_error($con);
 }

 ?>

我不知道我到底做错了什么。请帮我找出我在里面做错了什么。

f45qwnt8

f45qwnt81#

你叫一个变量 offset 在javascript中,但是 start 在php代码中。什么也不会跑,因为它永远不会进入太空 if 声明。
试试这个:

<?php

    if(isset($_POST["limit"],$_POST["offset"])){  //Change variable name here
        $con = mysqli_connect('localhost','root','','user_data') or 
            die(mysqli_error());

        $query = "SELECT * FROM `challenges` ORDER BY `id` DESC LIMIT {$limit} 
    OFFSET {$offset}";

        $result = mysqli_query($con,$query);
        while($row = mysqli_fetch_assoc($result))
        {
              echo '<p>'.$row["challenger_name"].'</p>';
        }
        mysqli_error($con);
     }

 ?>

相关问题