我用tp和ajax做了一个搜索加分页的功能。先写的分页代码,没有问题。然后再加上了搜索条件,返回第一页是没有问题的,但点击下方分页条的第二页后,页面就空白没有返回值了。请大家帮我看看:
<form> <input type="text" value="" placeholder="请输入搜索内容。" id="sousuolan"> <button id="sousuojian" onclick="return false;">搜索</button> </form> <div class="list"> <foreach name="list" item="vv"> <div class="tile">{$vv.user_id}</div> <div class="content">{$vv.user_name}</div> <hr /> </foreach> <div class="fenyetiao">{$page}</div> </div> /*这是用于搜索栏的点击效果设计*/ $(function(){ $('#sousuojian').click(function(){ var $searchword=$("#sousuolan").val(); if ($searchword=="") { alert("搜索内容不得为空!"); $("#sousuolan").focus(); return false; } $.ajax({ type:'post', url:'{:U('Dongzuo/search_page')}', data:{searchword:$searchword}, success:function(res){$(".list").html(res);} }) return false;}); }); /*这是用于分页条的点击效果设计*/ $(function(){ $(".fenyetiao a").live('click',function(){ var pageObj = this; var url = pageObj.href $.ajax({ type:'get', url:url, success:function(res){$(".list").html(res);} }) return false; }) }); /*这是控制器的模块*/ class DongzuoController extends BaseController { public function search_page() {$searchword = I('searchword'); $userinfo = D('UsersInfo'); $count = $userinfo->where("user_name like '%{$searchword}%'")->count(); $Page = new \Think\Page($count,5); $show = $Page->show(); $list = $userinfo->where("user_name like '%{$searchword}%'")->limit($Page->firstRow.','.$Page->listRows)->select(); if(IS_AJAX) { $this->assign('page',$show); $this->assign('list',$list); $html = $this->fetch('fenye/test1Page'); $this->ajaxReturn($html); } $this->display(); } } /*这是fetch的test1Page*/ <foreach name="list" item="vv"> <div class="tile">{$vv.user_id}</div> <div class="content">{$vv.user_name}</div> <hr /> </foreach> <div class="fenyetiao"> {$page} </div>
打开chrome,按下F12,点击Network和Console,开始查看错误信息并调试。
初步猜测,你用的jq版本不支持live方法,改成$(".fenyetiao ").on('click','a',function(){});