问题起源比较蛋疼,就是点击第二页及以后出现图中情况
查看源代码发现是这样的
页面主要情况:
解决办法主要思路:不进入分页链接,直接抓取其内容
1、控制器:
public function searchAdmin() {
$admin = D('Admin');
$limit = 2;
$searchPara = I('get.searchPara');
$adminList = $admin->searchAdmin($limit, $searchPara);
$string = "";
foreach ($adminList['list'] as $v) {
$string .= "
" . $v['admin_name'] . "" . $v['admin_realname'] . "" . $v['admin_tele'] . "" . $v['admin_email'] . "" . $v['admin_dep'] . "" . $v['admin_firstdep'] . "" . $v['admin_seconddep'] ."
详情";}
$page = $adminList['page'];
$string = $string . "
" . $page . "";// echo $string;
$this->ajaxReturn($string, 'EVAL');
}2、复制一份page类到\ThinkPHP\Library\Org\Util文件夹下,修改
3、Model
public function searchAdmin($limit, $word) {
$where['Admin_RealName|Admin_Name|Admin_Tele|Admin_Email|Admin_Dep|Admin_FirstDep|Admin_SecondDep'] = array('like', "%$word%");
$rs['count'] = $this->where($where)->count();
$Page = new \Org\Util\Page($rs['count'], $limit);
$rs['list'] = $this->where($where)->limit($Page->firstRow . ',' . $Page->listRows)->select();
$map = array();
$map['searchPara'] = $word;
foreach ($map as $key => $val) {
$Page->parameter[$key] = urlencode($val);
}
$rs['page'] = $Page->show();
return $rs;
}
4、js
$('.btn').click(function() {
if ($("#searchPara").attr("value") == "" || $("#searchPara").attr("value") == null) {
alert('请输入关键词!');
$("#searchPara").focus();
} else {
var action = $('form').attr('action');
var val = $('input[type=text]').val();
$.get(action,{searchPara:val},function (data) {
$('#table2').empty();
$('.fenye').empty();
$('#table2').html(data);
});
}
});
function fun(obj) {
$("#table2").load(obj.href);
return false;
}
纠结了三天成果,搜了很多但发现很少人遇到这样的问题,没用ajax+php分页是因为感觉比较麻烦,还是结合tp的分页类