thinkPHP5无刷新分页
- php控制器判断是否为ajax请求
$page=$articles->render();
$this->assign('page',$page);
$this->assign('articles', $articles);
if(request()->isAjax()){
return $this->fetch('articleList');
}
else {
return $this->fetch('articleIndex');
}
- 负责ajax请求渲染的模板
<div class="simplebox grid740">
<div class="titleh">
<h3>博文列表</h3>
</div>
<table id="myTable" class="tablesorter">
<thead>
<tr>
<th>#ID</th>
<th>作者</th>
<th>分类</th>
<th>标题</th>
<th>发布日期</th>
<th>评论数量</th>
<th>状态</th>
<th>操作</th>
</tr>
</thead>
<tbody>
{volist name='articles' id='article' key="k"}
<tr>
<td>{$k}</td>
<td>作者</td>
<td>{$article.c_name}</td>
<td>{$article.name}</td>
<td>{$article.publishtime|date="y-m-d",###}</td>
<td>{$article.id|count}</td>
<td>{$article.status}</td>
<td>
<form action="\article\{$article.id}\edit" name="edit">
<button>编辑</button>
</form>
<form action="\article\{$article.id}" name="delete" method="post">
<button onclick="return confirm('是否确定删除文章:{$article.c_name}?');">删除</button>
<input type="hidden" name="_method" value="DELETE">
</form>
</td>
</tr>
{/volist}
</tbody>
</table>
{$page}
</div>
- 正式访问页面执行ajax请求
{literal}
<script>
$(function () {
$("#list").on("click",".pagination a",function() {
$.get($(this).attr('href'),function(html){
$('#list').html(html);
});
return false;
})
})
</script>
{/literal}
<div id="list">
<div class="simplebox grid740">
<div class="titleh">