首页 > yii2 ajax 分页

yii2 ajax 分页

js代码
$(".pagination a").on('click',function(){
    $.post($(this).attr('href'),function(data){
        console.log(data);
    })
    return false;
})
控制器代码
public function actionIndex() {
        $model = new Dish();
        $where['status'] = 1;
        $info = $model->getPageList($where, 10, 'dishid desc');
        if(Yii::$app->request->isAjax){
            return $this->render('more',[
                'list' => $info['list'],
            ]);
        }else{
            return $this->render('index',[
                'list' => $info['list'],
                'page' => $info['page'],
            ]);
        }
    }

在运行的时候出现400 错误 在控制器内应该怎么写啊!


服务器端没接收到csrf

  1. 可以禁用csrf validation (不推荐)

  2. 如果你没有使用yii.js的话,就需要你自己来传了

【热门文章】
【热门文章】