php+ajax+jquery实现点击加载更多内容

2020-05-22 16:38:13易采站长站整理

require_once('connect.php');

$last = $_POST['last'];
$amount = $_POST['amount'];

$user = array('demo1','demo2','demo3','demo3','demo4');
$query=mysql_query("select * from say order by id desc limit $last,$amount");
while ($row=mysql_fetch_array($query)) {
$sayList[] = array(
'content'=>$row['content'],
'author'=>$user[$row['userid']],
'date'=>date('m-d H:i',$row['addtime'])
);
}
echo json_encode($sayList);

data.php接收前台页面提交过来的两个参数,$_POST[‘last’]即开始记录数,$_POST[‘amount’]即单次显示记录数,看SQL语句就明白,其实就是分页中用到的语句。

然后将查询的结果以JSON格式输出,PHP的任务就完成了。

最后来看下jquery.more.js的参数配置。

‘amount’      :   ’10’,           //每次显示记录数
‘address’     :   ‘comments.php’, //请求后台的地址
‘format’      :   ‘json’,         //数据传输格式
‘template’    :   ‘.single_item’, //html记录DIV的class属性
‘trigger’     :   ‘.get_more’,    //触发加载更多记录的class属性
‘scroll’      :   ‘false’,        //是否支持滚动触发加载
‘offset’      :   ‘100’,          //滚动触发加载时的偏移量

以上所述就是本文的全部内容了,希望大家能够喜欢。