thinkphp自带的Page类 + Ajax实现无刷新分页 有视频教程和源文件
2017-06-03 12:51
423 查看
前端代码: <div class="list"> <foreach name="list" item="vv"> <div class="title">{$vv.title}</div> <div class="content">{$vv.content}</div> <hr size="5" color="red" /> </foreach> <div class="page"> {$page} </div> </div> </body> <script> $(function(){ $(".page a").live('click',function(){ //直接用click点击事件因为js没刷新还是会出现跳转,on(“click”,function)事件测试有的页码也会出现跳转 var pageObj = this; var url = pageObj.href; $.ajax({ type:'get', url:url, success:function(res){ $(".list").html(res); } }) return false;//取消a链接的跳转 }) }) </script>
控制器:<?php namespace Home\Controller; use Think\Controller; class IndexController extends Controller { public function index(){ $article = M('article'); // 实例化User对象 $count = $article->where('1=1')->count();// 查询满足要求的总记录数 $Page = new \Think\Page($count,5);// 实例化分页类 传入总记录数和每页显示的记录数(25) $show = $Page->show();// 分页显示输出 // 进行分页数据查询 注意limit方法的参数要使用Page类的属性 $list = $article->where('1=1')->limit($Page->firstRow.','.$Page->listRows)->select(); if(IS_AJAX){ $this->assign('list',$list);// 赋值数据集 $this->assign('page',$show);// 赋值分页输出 $html = $this->fetch('Index/ajaxPage'); //另建一个html文件用来获取得到的分页内容 $this->ajaxReturn($html); } $this->assign('list',$list);// 赋值数据集 $this->assign('page',$show);// 赋值分页输出 $this->display(); // 输出模板 } }
ajaxPage页面: <foreach name="list" item="vv"> <div class="title">{$vv.title}</div> <div class="content">{$vv.content}</div> <hr size="5" color="red" /> </foreach> <div class="page"> {$page} </div>转载地址:http://www.thinkphp.cn/topic/33736.html 有视频和源文件哦!
相关文章推荐
- 在Thinkphp中使用AJAX实现无刷新分页
- 在Thinkphp中使用ajax实现无刷新分页的方法
- thinkphp中使用ajax实现无刷新分页
- VUEJS 实战教程第三章,利用laypage插件实现分页
- thinkphp下实现ajax无刷新分页
- 在Thinkphp中使用AJAX实现无刷新分页
- ThinkPHP实现ajax无刷新分页
- Thinkphp3.2自带分页功能实现方法
- 小型CRM项目(Page分页实现详细教程)
- thinkphp ajax 无刷新分页效果的实现
- OA项目 分页功能总结二 实现较为复杂的分页功能(资料来源于传智播客汤阳光的视频教程)
- PHP + AJAX 实现无刷新分页 不刷新页面实现分页 PHP AJAX
- thinkPHP5 使用laypage分页插件实现列表分页功能
- ajax 笔记--不用刷新实现数据的分页显示 2 (上)
- ajax 笔记--不用刷新实现数据的分页显示
- QTP9.2自带的视频教程
- 利用Ajax实现DataGrid无刷新分页
- ajax 笔记--不用刷新实现数据的分页显示 2 (上)
- 利用Ajax实现DataGrid无刷新分页
- 客户端回调实现gridView无刷新分页第一页