媛媛*小怪兽
If you have choices,choose the best! If you have no choices,do the best! 人生就是不断在学习路上进步的!!!!!!

搜索页面为ajax请求的,红框的为不可忽视部分

1.静态页面

<form name="admin_list_sea" class="form-search" method="get" action="{:url('Qus/index')}">
<div class="col-sm-3">
<div class="input-group">
<input type="text" id="key" value="" class="form-control" name="title" placeholder="输入需查询的文章名称" />
<span class="input-group-btn">
<button type="submit" class="btn btn-primary"><i class="fa fa-search"></i> 搜索</button>
</span>
</div>
</div>
</form>

2.js里面

var key=$('#key').val();
Ajaxpage();

function Ajaxpage(curr){
$.getJSON('{:url("Qus/index")}', {
page: curr || 1,key:key
}, function(data){ //data是后台返回过来的JSON数据
$(".spiner-example").css('display','none'); //数据加载完关闭动画
if(data==''){
$("#list-content").html('<td colspan="20" style="padding-top:10px;padding-bottom:10px;font-size:16px;text-align:center">暂无数据</td>');
}
});
}

3.控制器

 public function index(){
$map = [];
$count = Db::table('think_qus')->where($map)->order('id desc')->count();//计算总页面
$this->assign('count', $count);

//拿到了title
$title = input('title');
// var_dump($title);
if($title&&$title!=""){
$map['title'] = ['like',"%" . $title . "%"];
$map['status']=array('gt',"-1");
$count = Db::table('think_qus')->where($map)->order('id desc')->count();
$this->assign('count', $count);
}
$this->assign('title', $title);

// 查询状态为1的用户数据 并且每页显示10条数据 总记录数为$count(总共有多少条数据)
$list = Db::table('think_qus')->where($map)->order('id desc')->paginate(20,$count);
// 获取分页显示
$page = $list->render();
// 把分页数据赋值给模板变量list
$this->assign('list', $list);
// 模板变量赋值
$this->assign('page', $page);
// 渲染模板输出
return $this->fetch();
}

大功告成,欧克呐。。。。。。。。。。。。。。。。。。。。。。。。。。。。。耶!!!!!!

posted on 2018-02-07 11:31  媛味君  阅读(2565)  评论(0编辑  收藏  举报