JS <script type="text/javascript"> //定义全局变量,用于计算分页 var more_i = 1; $(‘#showmore‘).click(function() { $.ajax({ type : ‘get‘, url : ‘__URL__/ajax_more‘, data : { ‘evalue_id‘ : {$evalue_info.evalue_id}, ‘num‘ : more_i, }, dataType: ‘json‘, success : function(res) { if(res == 0){ alert(‘没有更多数据了‘); }else { $(‘#prev_more‘).before(res[‘info‘]); more_i = res[‘num‘] + 1; } }, }); }); </script>PHP,采用tp框架 /* AJAX加载更多 */ public function ajax_more() {//实例化模型 $doctor_evalue_reply = M(‘doctor_evalue_reply‘);//获取ajax传值过来的数据 $evalue_id = $this->_get(‘evalue_id‘,‘intval‘); $num = $this->_get(‘num‘,‘intval‘);//计算分页 $start = $num * 5; //获取数据 $condition[‘evalue_id‘] = $evalue_id; $reply_info = $doctor_evalue_reply ->field(‘reply_id,user_name,content,add_time‘) ->where($condition) ->limit($start . ‘,5‘) ->order(‘add_time desc‘) ->select(); if($reply_info === null) { $res = 0; }else {//服务器端将num数字++,传回客户端js调用。 $res[‘num‘] = $num++; //将数据拼装为html, foreach ($reply_info as $key => $value) { $temp = $start + $key + 1; $html .= ‘<tr class="‘.$vlaue[‘reply_id‘].‘">‘; $html .= ‘<td><input name="id[]" value="‘.$value[‘reply_id‘].‘" type="checkbox"/></td>‘; $html .= ‘<td>‘.$temp.‘</td>‘; $html .= ‘<td>‘.$value[‘user_name‘].‘</td>‘; $html .= ‘<td title="‘.$value[‘content‘].‘">‘.mb_substr($value[‘content‘],0,35,‘UTF-8‘).‘...</td>‘; $html .= ‘<td>‘.date(‘Y-m-d H:i:s‘,$value[‘add_time‘]).‘</td>‘; $html .= ‘<td><input type="button" value="删除" class="button" onClick="if (confirm(\‘你确定删除该医生吗?\‘)) del(‘.$value[‘reply_id‘].‘);" /></td>‘; $html .= ‘</tr>‘; } $res[‘info‘] = $html; }//json形式返回 echo json_encode($res); }
时间: 2024-10-08 21:53:59