首先頁面要獲取到一下參數
當前頁碼:page
總頁碼:total
html:
<?php foreach ($list as $v){?>
<div class="receipt margin0 display_flex">
<div class="flex_1 text_left size_13px">
<p class="color_black"><?php echo $v['event_type']?></p>
<p class="receipt_time color_Palegray"><?php echo $v['created_at']?></p>
</div>
<div class="receipt_text flex_1 color_black size_14px text_right"><?php echo $v['amount']?> USDT</div>
</div>
<?php }?>
<input type="hidden" id="page" value="<?php echo $page?>">
<span class="jiazai"></span>
<div id="next">點擊加載更多</div>
js:
$("#next").click(function () {
var page=$('#page').val();
$.ajax({
type: "get",
data: {page: page},
url: "/****/***",
success: function (data) {
obj = eval("("+data+")");
if(obj.status=='0000' && obj.list!=''){
let html = '';
$.each(obj.list,function (index,v){
html+=' <div class="receipt margin0 display_flex">';
html+=' <div class="flex_1 text_left size_13px">';
html+=' <p class="color_black">'+v.event_type+'</p>';
html+=' <p class="receipt_time color_Palegray"> '+v.created_at+'</p>';
html+=' </div>';
html+=' <div class="receipt_text flex_1 color_black size_14px text_right">'+v.amount+' USDT</div>';
html+=' </div>';
});
if(obj.page==obj.total){
$('#next').empty();
html+='<div id="">沒有更多</div> ';
}
$('.jiazai').append(html);
$('#page').val(obj.page);
}
}
});
})
php:yii
$pageSize = 10; //每頁顯示的數量
$total = new yii\data\Pagination(['totalCount' =>UserWalletRecord::find()
->where(array('userid'=>$userId,'wallet_type'=>3))
->count(), 'pageSize' => $pageSize]);
if (Yii::$app->request->isAjax) {
$page = HtmlPurifier::process(Yii::$app->request->get("page"));//當前頁碼
$page+=1;
$list=UserWalletRecord::find()->offset(($page-1)*$pageSize)->limit($pageSize)
->where(array('userid'=>$userId,'wallet_type'=>3))
->select('amount,event_type,pay_type,wallet_amount,note,created_at')
->asArray()
->orderBy(['created_at'=>SORT_DESC])->all();
$data['status']='0000';
$data['list']=$list;
$data['page']=$page;
$data['total']=(int)$total->pageCount;
return json_encode($data);
}