<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
</head>
<body>
<div id="test">
{include file="ajaxpage" /}
</div>
<script type="text/javascript">
$(".pagination a").click(function(){
var url = $(this).attr('href');
$.ajax({
'type' : 'get',
'url' : url,
succes:function(data){
$('#test').html(data);
}
})
return false;
});
</script>
</body>
</html>ajaxpage.html的代码如下:<table border="1">
<thead>
<tr>
<th>编号</th>
<th>名称</th>
<th>货号</th>
<th>库存</th>
<th>排序</th>
</tr>
</thead>
<tbody>
{foreach name="list" item="goods"}
<tr>
<td>{$goods.goods_id}</td>
<td>{$goods.goods_name}</td>
<td>{$goods.goods_sn}</td>
<td>{$goods.goods_number}</td>
<td>{$goods.sort_order}</td>
</tr>
{/foreach}
</tbody>
<tfoot>
{$page}
</tfoot>
</table>然后控制器部分Index.php代码如下:<?php
namespace app\index\controller;
use think\Controller;
class Index extends Controller
{
public function index()
{
$list = db('goods')->paginate();
$page = $list->render();
$this->assign('list',$list);
$this->assign('page',$page);
if (request()->isAjax())
{
return $this->fetch('ajaxpage');
}
else
{
return $this->fetch('index');
}
}
} 最佳答案