Jquery实现无刷新分页
index.php
<?php
header("Content-Type:text/html;charset=utf-8");
?>
<html>
<head>
<title>JQ-无刷新分页 by:siyuantlw</title>
<style>
A{text-decoration:none;}
A:link {COLOR:#33CCFF;}
A:active {COLOR:#FF6666;}
A:visited {COLOR:#33CCFF;}
A:hover {COLOR:#FF6699; TEXT-DECORATION: underline;position:relative;left:1px;top:1px}
</style>
<script src="jquery-1.5.1.js"></script>
<script language="javascript">
$(document).ready(function(){
changepage(1);
});
function changepage(page){
$.post("sql.php",{page:page},function(data){
$("#test").html(data);
});
}
</script>
</head>
<body>
<ul id="test"></ul>
</body>
</html>
sql.php
<?php
mysql_connect("","root","");
mysql_select_db("test");
mysql_query("set names utf8");
if(isset($_POST["page"])){
@$page = max(1, intval($_POST["page"]));
$pagesize=10;
$startindex=($page-1)*$pagesize;
$sql="SELECT * FROM test ORDER BY id LIMIT $startindex,$pagesize";
$rec=mysql_query($sql);
while($row=mysql_fetch_array($rec)){
$str.="<li>".$row["uname"]."</li>";
}
$num=mysql_num_rows(mysql_query("select * from test"));
$pagenum=@ceil($num/$pagesize);
for($i=1;$i<=$pagenum;$i++){
if($page==$i){
$str.="<a href='javascript:void(0)' onclick=changepage(".$i.")>[".$i."]</a> ";
}else{
$str.="<a href='javascript:void(0)' onclick=changepage(".$i.")>".$i."</a> ";
}
}
echo $str;
}else{
die();
}
?>
test数据库表中test表
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for test
-- ----------------------------
DROP TABLE IF EXISTS `test`;
CREATE TABLE `test` (
`id` int(10) NOT NULL auto_increment,
`uname` char(50) character set utf8 NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=gb2312 COLLATE=gb2312_bin;
-- ----------------------------
-- Records
-- ----------------------------
INSERT INTO `test` VALUES ('1', 'aaaaaaaaaaa');
INSERT INTO `test` VALUES ('2', 'bbbbbbbbbbbb');
INSERT INTO `test` VALUES ('3', 'cccccccccccc');
INSERT INTO `test` VALUES ('4', 'dddddddddddddddd');
INSERT INTO `test` VALUES ('5', 'eeeeeeeeeee');
INSERT INTO `test` VALUES ('6', 'ffffffffff');
INSERT INTO `test` VALUES ('7', 'ggggggggggggggg');
INSERT INTO `test` VALUES ('8', 'hhhhhhhhhhhh');
INSERT INTO `test` VALUES ('9', 'jjjjjjjjjjjjjjjj');
INSERT INTO `test` VALUES ('10', 'kkkkkkkkkkk');
INSERT INTO `test` VALUES ('11', 'mmmmmmmmmmm');
INSERT INTO `test` VALUES ('12', 'cccccccccccccccccc');
INSERT INTO `test` VALUES ('13', 'bbbbbbbbbbbb');
INSERT INTO `test` VALUES ('14', 'ooooooooooooooooo');
INSERT INTO `test` VALUES ('15', 'pppppppppppp');
INSERT INTO `test` VALUES ('16', 'aaaaaaaaaaaaaaa');
INSERT INTO `test` VALUES ('17', 'ggggggggggggggggg');
INSERT INTO `test` VALUES ('18', 'dddddddddddddddd');
INSERT INTO `test` VALUES ('19', 'cccccccccccccc');
INSERT INTO `test` VALUES ('20', 'xxxxxxxxxx');
INSERT INTO `test` VALUES ('21', 'zzzzzzzzzzzzzzz');
INSERT INTO `test` VALUES ('22', 'oooooooooooooooooooo');
INSERT INTO `test` VALUES ('23', 'iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii');
INSERT INTO `test` VALUES ('24', 'uuuuuuuuuuuuuuuuuuuuuuuuuuuuu');
INSERT INTO `test` VALUES ('25', 'yyyyyyyyyyyyyyyyyy');
INSERT INTO `test` VALUES ('26', 'ttttttttttttttttttttttttttt');
INSERT INTO `test` VALUES ('27', 'rrrrrrrrrrrrrrrrrrrrrrrr');
INSERT INTO `test` VALUES ('28', 'eeeeeeeeeeeeeeeeeeeee');
INSERT INTO `test` VALUES ('29', 'wwwwwwwwwwwwwwwwwwwww');
INSERT INTO `test` VALUES ('30', 'qqqqqqqqqqqqq');
INSERT INTO `test` VALUES ('31', 'aaaaaaaaaaa');
INSERT INTO `test` VALUES ('32', 'zzzzzzzzzzzzz');
INSERT INTO `test` VALUES ('33', 'ssssssssssd');
INSERT INTO `test` VALUES ('34', 'dddddddddddddddddddddddd');
INSERT INTO `test` VALUES ('35', 'fffffffffffffffffffff');
INSERT INTO `test` VALUES ('36', 'vvvvvvvvvvvvvvvvvvvv');
INSERT INTO `test` VALUES ('37', 'bbbbbbbbbbbbbbbbbnb');
INSERT INTO `test` VALUES ('38', 'nnnnnnnnnnnnnn');
INSERT INTO `test` VALUES ('39', '2222222222222');
INSERT INTO `test` VALUES ('40', '1111111111111');
INSERT INTO `test` VALUES ('41', '3333333333333');
INSERT INTO `test` VALUES ('42', '44444444444');
INSERT INTO `test` VALUES ('43', '5555555555555');
INSERT INTO `test` VALUES ('44', '6666666666666');
INSERT INTO `test` VALUES ('45', '7777777777777');
INSERT INTO `test` VALUES ('46', '8888888888888');
INSERT INTO `test` VALUES ('47', '999999999999999');
INSERT INTO `test` VALUES ('48', '000000000000');