滚屏加载更多数据,适合评论等页面 本例的数据库很简单,一看就明了 复制代码 代码如下: $query=mysql_query("select * from content order by id desc limit 0,10"); while ($row=mysql_fetch_array($query)) { ?> js文件 复制代码 代码如下: <BR>$(function(){ <BR>var winH = $(window).height(); //页面可视区域高度 <BR>var i = 1; <BR>$(window).scroll(function () { <BR>var pageH = $(document.body).height(); <BR>var scrollT = $(window).scrollTop(); //滚动条top <BR>var aa = (pageH-winH-scrollT)/winH; <BR>if(aa<0.02){ <BR>$.getJSON("result.php",{page:i},function(json){ <BR>if(json){ <BR>var str = ""; <BR>$.each(json,function(index,array){ <BR>var str = "<div class=\"single_item\"><div class=\"element_head\">"; <BR>var str = str + "<div class=\"date\">"+array['date']+" "; var str = str + ""+array['author']+""; var str = str + ""+array['content']+""; $("#container").append(str); }); i++; }else{ $(".nodata").show().html("别滚动了,已经到底了。。。"); return false; } }); } }); }); result.php 复制代码 代码如下: include("conn.php"); $page = intval($_GET['page']); //获取请求的页数 $start = $page*5; $query=mysql_query("select * from content order by id desc limit $start,5"); while ($row=mysql_fetch_array($query)) { $arr[] = array( 'content'=>$row['message'], 'author'=>$row['id'], 'date'=>date('m-d H:i',strtotime($row['updatetime'])) ); } echo json_encode($arr); //转换为json数据输出 ?>