效果:
html:
<div class="wrap "> <div class="teacher_box"> {volist name='$archivesData' id="vo"} <div class="teacher_item"> <div class="left_content"> <img src="{$vo.thumb}"> </div> <div class="right_content"> <div class="text1">{$vo.title}</div> <div class="text2">{$vo.keywords}</div> <div class="text3">{$vo.description}</div> </div> </div> {/volist} </div> <div class="teacher_more">加载更多</div> <div class="teacher_null">没有数据了</div> <input type="hidden" name="" id="page" value="1"> </div>
js:
<script> $(".teacher_more").click(function () { request_page = 0; current_page = $("#page").val(); request_page = parseInt(current_page) + 1; url = "ajax_teacher"; postData = { 'request_page': request_page }; $.post(url, postData, function (result) { html = ''; if (result.status == 1) { $page = $("#page").val(request_page); data = result.data; $.each(data, function (index, value) { a = "<div class='teacher_item'><div class='left_content'><img src='" + value.thumb + "'></div><div class='right_content'><div class='text1'>" + value.title + "</div><div class='text2'>" + value.keywords + "</div><div class='text3'>" + value.description + "</div></div></div>" html = html + a; }); $(".teacher_box .teacher_item:last-child").after(html); //没有数据了就去掉more if (data.length < 2) { $(".teacher_more").css('display', 'none'); $(".teacher_null").css('display', 'flex'); } } if(result.status == 0){ layer.msg('加载数据失败'); } }, 'json'); }); </script>
PHP:
public function ajax_teacher(){ $page=input('request_page'); if(!is_numeric($page)){ return json([ 'status'=>0, 'data'=>[] ]); } $archivesData=Db::name('archives')->where('cate_id',1)->order('id desc')->page($page,2)->select(); return json([ 'status'=>1, 'data'=>$archivesData ]); }