Home >PHP Framework >YII >yii2 post failed (400 error) solution
yii2 post400 error solution:
The first solution is to turn off Csrf
public function init(){ $this->enableCsrfValidation = false; }
The second solution is to add it to the form Hidden domain
<input name="_csrf" type="hidden" id="_csrf" value="<?= Yii::$app->request->csrfToken ?>">
The third solution is to add the _csrf field in AJAX
var csrfToken = $('meta[name="csrf-token"]').attr("content"); $.ajax({ type: 'POST', url: url, data: {_csrf:csrfToken}, success: success, dataType: dataType });
PHP Chinese website, there are a lot of free Yii introductory tutorials, everyone is welcome to learn !
The above is the detailed content of yii2 post failed (400 error) solution. For more information, please follow other related articles on the PHP Chinese website!