Home > Article > PHP Framework > Solution to 400 error in yii2
400 error solution in yii2:
The first solution is to close Csrf
Close it in the controller
public function init(){ $this->enableCsrfValidation = false; }
The second solution is to add a hidden field to the form
<input name="_csrf" type="hidden" id="_csrf" value="<?= Yii::$app->request->csrfToken ?>">
The third solution is to add the _csrf field to AJAX
var csrfToken = $('meta[name="csrf-token"]').attr("content"); $.ajax({ type: 'POST', url: url, data: {_csrf:csrfToken}, success: success, dataType: dataType });
Related tutorial recommendations: yii framework
The above is the detailed content of Solution to 400 error in yii2. For more information, please follow other related articles on the PHP Chinese website!