AJax技术

Thinkphp+ajax实现无刷新分页

字号+ 作者:H5之家 来源:H5之家 2017-02-25 14:01 我要评论( )

三零网提供网络编程、 PHP编程 的技术文章Thinkphp+ajax实现无刷新分页给大家,希望大家喜欢,关键词Thinkphp+ajax实现无刷新分页

这里为大家带来一篇 。Thinkphp+ajax实现无刷新分页 希望对您的学习研究PHP有帮助,具体参考描述如下:

在Thinkphp目录的Lib\ORG\Util\目录里新建AjaxPage.class.php,写入一下内容:

<?php // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK IT ] // +---------------------------------------------------------------------- // | Copyright (c) 2009 All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( ) // +---------------------------------------------------------------------- // | Author: liu21st <liu21st@gmail.com> // +---------------------------------------------------------------------- // $Id: Page.class.php 2712 2012-02-06 10:12:49Z liu21st $ class AjaxPage { // 分页栏每页显示的页数 public $rollPage = 5; // 页数跳转时要带的参数 public $parameter ; // 默认列表每页显示行数 public $listRows = 20; // 起始行数 public $firstRow ; // 分页总页面数 protected $totalPages ; // 总行数 protected $totalRows ; // 当前页数 protected $nowPage ; // 分页的栏的总页数 protected $coolPages ; // 分页显示定制 protected $config = array('header'=>'条记录','prev'=>'上一页','next'=>'下一页','first'=>'第一页','last'=>'最后一页','theme'=>' %totalRow% %header% %nowPage%/%totalPage% 页 %upPage% %downPage% %first% %prePage% %linkPage% %nextPage% %end%'); // 默认分页变量名 protected $varPage; public function __construct($totalRows,$listRows='',$ajax_func,$parameter='') { $this->totalRows = $totalRows; $this->ajax_func = $ajax_func; $this->parameter = $parameter; $this->varPage = C('VAR_PAGE') ? C('VAR_PAGE') : 'p' ; if(!empty($listRows)) { $this->listRows = intval($listRows); } $this->totalPages = ceil($this->totalRows/$this->listRows); //总页数 $this->coolPages = ceil($this->totalPages/$this->rollPage); $this->nowPage = !empty($_GET[$this->varPage])?intval($_GET[$this->varPage]):1; if(!empty($this->totalPages) && $this->nowPage>$this->totalPages) { $this->nowPage = $this->totalPages; } $this->firstRow = $this->listRows*($this->nowPage-1); } public function setConfig($name,$value) { if(isset($this->config[$name])) { $this->config[$name] = $value; } } public function show() { if(0 == $this->totalRows) return ''; $p = $this->varPage; $nowCoolPage = ceil($this->nowPage/$this->rollPage); $url = $_SERVER['REQUEST_URI'].(strpos($_SERVER['REQUEST_URI'],'?')?'':"?").$this->parameter; $parse = parse_url($url); if(isset($parse['query'])) { parse_str($parse['query'],$params); unset($params[$p]); $url = $parse['path'].'?'.http_build_query($params); } //上下翻页字符串 $upRow = $this->nowPage-1; $downRow = $this->nowPage+1; if ($upRow>0){ $upPage="<a href='javascript:".$this->ajax_func."(".$upRow.")'>".$this->config['prev']."</a>"; }else{ $upPage=""; } if ($downRow <= $this->totalPages){ $downPage="<a href='javascript:".$this->ajax_func."(".$downRow.")'>".$this->config['next']."</a>"; }else{ $downPage=""; } // << < > >> if($nowCoolPage == 1){ $theFirst = ""; $prePage = ""; }else{ $preRow = $this->nowPage-$this->rollPage; $prePage = "<a href='javascript:".$this->ajax_func."(".$preRow.")'>上".$this->rollPage."页</a>"; $theFirst = "<a href='javascript:".$this->ajax_func."(1)' >".$this->config['first']."</a>"; } if($nowCoolPage == $this->coolPages){ $nextPage = ""; $theEnd=""; }else{ $nextRow = $this->nowPage+$this->rollPage; $theEndRow = $this->totalPages; $nextPage = "<a href='javascript:".$this->ajax_func."(".$nextRow.")' >下".$this->rollPage."页</a>"; $theEnd = "<a href='javascript:".$this->ajax_func."(".$theEndRow.")' >".$this->config['last']."</a>"; } // 1 2 3 4 5 $linkPage = ""; for($i=1;$i<=$this->rollPage;$i++){ $page=($nowCoolPage-1)*$this->rollPage+$i; if($page!=$this->nowPage){ if($page<=$this->totalPages){ $linkPage .= " <a href='javascript:".$this->ajax_func."(".$page.")'> ".$page." </a>"; }else{ break; } }else{ if($this->totalPages != 1){ $linkPage .= " <span>".$page."</span>"; } } } $pageStr = str_replace( array('%header%','%nowPage%','%totalRow%','%totalPage%','%upPage%','%downPage%','%first%','%prePage%','%linkPage%','%nextPage%','%end%'), array($this->config['header'],$this->nowPage,$this->totalRows,$this->totalPages,$upPage,$downPage,$theFirst,$prePage,$linkPage,$nextPage,$theEnd),$this->config['theme']); return $pageStr; } } ?>

控制器里写入以下内容:

 

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

相关文章
  • PHP浅析AJAX技术的使用方法

    PHP浅析AJAX技术的使用方法

    2017-01-17 16:00

  • asp.net Mvc4 使用ajax结合分页插件实现无刷新分页

    asp.net Mvc4 使用ajax结合分页插件实现无刷新分页

    2017-01-15 11:03

  • Popup对象实现右键菜单

    Popup对象实现右键菜单

    2017-01-13 11:05

  • PHP框架Laravel入门教程

    PHP框架Laravel入门教程

    2017-01-02 09:01

网友点评