index控制器:
$posts = PostsModel::where('course_id',$courseId)->order('sort asc')->paginate($this->coursePostList,false,[ 'type' => 'Bootstrap', 'var_page' => 'page', 'path'=>"javascript:AjaxPage($courseId,[PAGE]);" ]); 前台html:
<div class="raw-page">{$posts|raw}</div> 前台js:
const AjaxPage = function(courseId,page){ $.ajax({ url:"{:url('listPosts')}", type:'post', dataType:'json', data: {"vpage":page,course_id:courseId}, success:function(data){ if(data.status == 1){ $("#list_posts").html(data.message); }else{ let index = layer.alert(data.message, { icon: 0, skin: 'layer-ext-moon' }, function() { layer.close(index); }); } } }); } 后台异步分页方法: public function listPosts(){ if(Request::isAjax()){ $page = Request::param('vpage'); $courseId = Request::param('course_id'); $posts = PostsModel::where('course_id',$courseId)->order('sort asc')->paginate($this->coursePostList,false,[ 'type' => 'Bootstrap', 'var_page' => 'page', 'page'=>$page, 'path'=>"javascript:AjaxPage($courseId,[PAGE]);" ]); $this->assign('posts',$posts); $msg = $this->fetch()->getContent(); return resMsg(1, $msg,'index'); }else{ return resMsg(-1,$this->_message['request_wrong'], 'index'); } }
更多精彩内容:各种AI课程、技能课程、黑科技软件、网站小程序源码、副业小项目、PPT模板等精品素材、电商课程、推广引流课程等,尽在 天边资源网 。