connect.php
<?php
$host="localhost";
$db_user="root";
$db_pass="root";
$db_name="food";
$timezone="Asia/Shanghai";
$link=mysql_connect($host,$db_user,$db_pass);
mysql_select_db($db_name,$link);
mysql_query("SET names UTF8");
header("Content-Type: text/html; charset=utf-8");
date_default_timezone_set($timezone); //北京时间
?>
pages.php
<?php
include_once('connect.php');
$page = intval($_POST['pageNum']);
$result = mysql_query("select id from food");
$total = mysql_num_rows($result);//总记录数
$pageSize = 6; //每页显示数
$totalPage = ceil($total/$pageSize); //总页数
$startPage = $page*$pageSize;
$arr['total'] = $total;
$arr['pageSize'] = $pageSize;
$arr['totalPage'] = $totalPage;
$query = mysql_query("select id,title,pic from food order by id asc limit $startPage,$pageSize");
while($row=mysql_fetch_array($query)){
$arr['list'][] = array(
'id' => $row['id'],
'title' => $row['title'],
'pic' => $row['pic'],
);
}
//print_r($arr);
echo json_encode($arr);
?>
index.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="ajax分页,jquery,php" />
<meta name="description" content="jquery+ajax+msql+php上拉加载或者jquery+ajax+msql+php滚动条向下滚动加载" />
<title>jquery+ajax+msql+php上拉加载或者jquery+ajax+msql+php滚动条向下滚动加载</title>
<style type="text/css">
body{
width:1349px;
height:auto;
margin:0;
padding:0;
}
#main{
width:980px;
margin:0 auto;
height:auto;
text-align:center
}
.nodata{
w