ajax分页 (jquery)

ajax分页 (jquery)

public function index()
{
$page=Request::instance()->param("page");//接收值
$mr=empty($page)?1:$page;
$count=Db::table("user")->count();//条数
$leng=4;//每页显示的条数
$sum_page=ceil($count/$leng);
$limit=($mr-1)*$leng;
$res=Db::table("user")->limit($limit,$leng)->select();
$this->assign("res",$res);
$this->assign("sum_page",$sum_page);
return view();
}

ajax分页 (jquery)

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<center>
<table border="1">
<tr>
<td>ID</td>
<td>姓名</td>
<td>邮箱</td>
<td>时间</td>
</tr>
<tbody id="tb">
{volist name="res" id="v"}
<tr id="{$v.u_id}">
<td>{$v.u_id}</td>
<td class="change">{$v.u_name}</td>
<td>{$v.u_yx}</td>
<td>{$v.u_time}</td>

</tr>
{/volist}
</tbody>
</table>
<input type="hidden" class="mr_page" value="1">
<input type="hidden" class="sum_page" value="{$sum_page}">
<a href="ajaxscript:void(0);" class="page">首页</a>
<a href="ajaxscript:void(0);" class="page">上一页</a>
<a href="ajaxscript:void(0);" class="page">下一页</a>
<a href="ajaxscript:void(0);" class="page">尾页</a>

<script src="__STATIC__/js/jquery-3.1.1.min.js"></script>
<script>

 

ajax分页 (jquery)

$(document).on("click",".page",function () {
var old=$(this).text();
var mr_page= $(".mr_page").val();
var sum_page=$(".sum_page").val();
var page="";
if(old=="首页"){
page=1;
}else if(old=="上一页"){
page=parseInt(mr_page)-1<=0?1:parseInt(mr_page)-1;

}else if(old=="下一页"){
page=parseInt(mr_page)+1>=sum_page?sum_page:parseInt(mr_page)+1;
}else {
page=sum_page;
}
$.post(
"{:url('node/json')}",
{
page:page
},
function (data) {
var json=(JSON.parse(data));
var str="";
$.each(json,function (k,v) {
str+="<tr>";
str+="<td>"+v.u_id+"</td>";
str+="<td>"+v.u_name+"</td>";
str+="<td>"+v.u_yx+"</td>";
str+="<td>"+v.u_time+"</td>";
str+="</tr>";
});
$("#tb").html(str);
$(".mr_page").val(page);

}
);

});

ajax分页 (jquery)

public function json(){
$page=Request::instance()->param("page");

$mr=empty($page)?1:$page;
$count=Db::table("user")->count();
$leng=4;
$sum_page=ceil($count/$leng);
$limit=($mr-1)*$leng;
$res=Db::table("user")->limit($limit,$leng)->select();
echo json_encode($res);
}

 

上一篇:欢乐SSL初二组周六赛【2019.4.27】


下一篇:Hadoop(MapReduce)性能优化