ThinkPHP & Jquery Ajax分页演示
演示一下jquery 处理json 并根据静态html模板生成相关内容
IndexAction 文件的代码
- class IndexAction extends Action
- {
- public function index()
- {
- $Page = D('Page');
-
- import("ORG.Util.Page");
- $count = $Page->count();
- $p = new Page($count,10);
-
- $json['list'] = $Page->findAll('','','id DESC',$p->firstRow.','.$p->listRows);
- $json['page'] = $this->ajax_page($p->show(true));
-
- $json = json_encode($json);
-
- if(empty($_GET['do']))
- {
- $this->assign('json',$json);
- $this->display();
- }
- else
- {
- echo $json;
- }
- }
-
- //--> ajax分页扩展
- public function ajax_page($page_array=array(),$step=10)
- {
- if ($page_array['totalPages'] >1)
- {
- $page['first'] = 1;
-
- $pre = intval($page_array['nowPage']/$step);
- $pre >0 ? $first = $page_array['nowPage']-$step : $first = $pre*$step+1 ;
- $pre >0 ? $end = $page_array['nowPage']+$step : $end = ($pre+1)*$step;
- if ($end >$page_array['totalPages'])
- {
- $first = $page_array['totalPages'] - $step;
-