tp5 ajax分页 写的真好

https://blog.csdn.net/qq_31065757/article/details/85393479

<!DOCTYPE HTML>
<html>
<head>
	<meta charset="utf-8">
    <title>{$name}</title>
    <link href="__STATIC__/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div>{$name}</div>
<div>
    <table border="1">
        <thead>
            <tr>
                <th  style="width: 60px">ID</th>
                <th  style="width: 160px">名称</th>
            </tr>
        </thead>
        <tbody  id="content">
        </tbody>
    </table>
    <div id="page"></div>
</div>
 
</body>
<script src="__STATIC__/js/jquery/1.9.1/jquery.js"></script>
<script>
    window.THINK_ROOT = '{:\\think\\Request::instance()->root()}';
    function Tp5AjaxPage(page) {
        $.ajax({
            url:THINK_ROOT+'/index/bbb',
            type:'post',
            dataType:'json',
            data: {page:page},
            success:function(res){
                console.log(res);
                var list = res.data;
                if(list.length !== 0){
                    $("#content").empty();
                    for(var key in list) {
                        $("#content").append('<tr>' +
                            '<td>'+list[key].id+'</td>' +
                            '<td>'+list[key].name+'</td>' +
                            '</tr>'
                        );
                    }
                    $("#page").html(res.page_html);
                }
            }
        });
    }
    //初始化
    Tp5AjaxPage(1);
</script>
</html>
class Index extends Controller
{
 
    public function aaa(){
        $this->view->assign('name','thinkphp5分页paginate之ajax请求');
        return $this->view->fetch();
    }
    public function bbb(){
        $page = 1;
        if(request()->param('page')){
            $page = request()->param('page');
        }
        $config = [
            'page' => $page,
            'var_page' => 'page',
            'path'=>'javascript:Tp5AjaxPage([PAGE]);',
        ];
        $listRows = 1;
        $res = Db::name('sys_role')->paginate($listRows,false,$config);
        $list = $res->toArray();
        $list['page_html'] = $res->render();
        return json($list);
    }
}

完成