Yii2 兼容AJAX加载分页

1.在控制器修改分页

if (Yii::$app->request->isAjax) {
    return $this->renderPartial('index', [
        'pagination'  =>  $pagination
    ]);
} else {
    return $this->render('index', [
        'pagination'  =>  $pagination
    ]);
}

2.在视图中添加代码

 $pagination,
    ]);
?>

registerJs("$(document).on('click','.pagination a',function(e){
    e.preventDefault();
    var url=$(this).attr('href');
    $.get(url,function(msg){
        $('.listbox').append(msg);
    });
});", \yii\web\View::POS_END);
?>

你可能感兴趣的:(php,yii)