0

我正在尝试使用 ajax php 和 jQuery 创建无休止的分页。php 脚本有效,但我无法让 ajax 实现下一行。

<script type="text/javascript">
  $(document).scroll(function(){
   var h = $('#content').height() * .6;
   var startrow = 10;
      if($(window).scrollTop() + $(window).height() > h){
       $.ajax(
       {
              url: "morerows.php",
              type:GET,
              data: startrow
              })
       }
   });  
</script>

这是被调用的文件,它与从数据库中提取的第一行格式相同

<?php
  $startrow = $_GET['startrow'];
  $dbc = @mysqli_connect('localhost', 'cgauss', 'cgauss', 'livve');
  $q = "SELECT * FROM users ORDER BY id DESC LIMIT $startrow, 10";
  $r = @mysqli_query($dbc, $q);
  $i = 1;
 while($page = mysqli_fetch_assoc($r)){          
    echo'<div class="post'.$i.'"><h1 class="ptitle'.$i.' ptitle">'.$page['name'] .' <span class="black">'.$page['type']. '</span>:</h1><br/>';
    echo'<div class="goal'.$i.'">The Goal:<p class="goalp'.$i.' goalp">  '. $page['goal'].'</p></div><br/>';
    echo'<div class="media'.$i.'">';
     $type = substr($page['imagename'],-3);
    if($type == "jpg" || $type == "png" || $type == "gif")
{
    echo '<div class="image'.$i.'"><img id="theimage" class="lazy" src="uploaded/'.$page['imagename'].'" data-original="uploaded/'.$page['imagename'].'" width="85%" /> </div>';
    }
else if($type == "mp4"){
    echo '<video id="my_video_1" class="video-js vjs-default-skin" controls preload="auto" width="85%"  poster="my_video_poster.png" data-setup="{}">
    <source src=uploaded/'.$page['imagename'].' type="video/mp4">
    </video>';
}else{
    echo '';
}
 echo'</div>';
 echo'<div class="description'.$i.' description">Description:<p class="descriptionp">  '.$page['comment'].'</p></div></div><b/>';
 $startrow = $startrow +10;
         $i++;
         if($i == 5){
             $i =1;
         }

         }
         ?>
4

1 回答 1

2

您必须使用 ajax done 函数才能对从 ajax 检索到的数据进行处理。例如:

$.ajax({
  type: "GET",
  url: "morerows.php",
  data: startrow
}).done(function( msg ) {
  alert( "Data: " + msg );
});
于 2013-08-13T07:44:35.070 回答