tp5 点击加载更多

html

var page = 2; //从第二页开始获取数据
    // 点击查看更多
    $("#getmoreare").click(function(){
        
        $.ajax({
          url: '地址',
          type: 'POST',
          dataType: 'json',
          data: {page: page},
          complete: function(xhr, textStatus) {
            //called when complete
          },
          success: function(res) {
            
            var str = "";//定义变量保存内容
            
            
            $.each(res,function(index,array){

                id = array['id'];
                title = array['title'];
                img = array['timage'];
                alicon = array['content'];
                time = array['createtime'];


                if (array['pacbull']) {
                    $("#getmoreare").html("没有更多内容了..");
                }else{
                    str += '<li>'
                            +'<a href="/Article/artdetail?id='+id+'">'
                                +'<div class="zizou_consulting_content_timg">'
                                    +'<img src="'+img+'" alt="">'
                                +'</div>'
                                +'<div class="zizou_consulting_content_cen">'
                                    +'<div>'
                                        +'<h4>'+title+'</h4>'
                                    +'</div>'
                                    +'<div class="zizou_consulting_content_cen_removeHtmltag">'+alicon+'</div>'
                                    +'<div class="zizou_consulting_content_cen_time">'+time+'</div>'
                                +'</div>'
                            +'</a>'
                        +'</li>';

                }
            })
            $('.zizou_consulting_content ul:last').append(str);
            
            var pageval = page++;//页数+1
            $("#page").val(pageval);

          },
          error: function(xhr, textStatus, errorThrown) {
            //called when there is an error
          }
        });
        
    })

后台

		$where = [];
        //获取请求页面数
        $page = $this->request->post('page') ? $this->request->post('page') : 1;
         $where = [
                'switch'=>'1',
            ];
        $num = 6;//请求条数
        $more_data = amodel::where($where)->order('weigh','desc')->page($page,$num)->select()->toArray();
        $count = count($more_data);
        foreach ($more_data as $k=>$v){
            $more_data[$k]['createtime'] = date('Y-m-d', $v['createtime']);
            // 去除html标签,并截取40个字符,前台就不加载全部文章,以免增加耗时
            $tagecontent = strip_tags($v['content']);
            $pattern = '/\s/';//去除空白
            $content = preg_replace($pattern, '', $tagecontent);
            $more_data[$k]['content'] = mb_substr($content,0,40, "UTF-8");
        }
        if ($this->request->isPost()) {
            if ($count < $num) {
                $more_data[]['pacbull'] = '0';//到尾页返回0
            }
            return json($more_data);
            exit;
        }
        $this->assign('more_data',$more_data);
        $this->assign(['num'=>$num,'count'=>$count]);```

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

时间轴-小文同学

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值