Home > PHP Framework > YII > yii2 post failed (400 error) solution

yii2 post failed (400 error) solution

Release: 2019-12-17 13:56:25
Original
2944 people have browsed it

yii2 post failed (400 error) solution

yii2 post400 error solution:

The first solution is to turn off Csrf

public function init(){
    $this->enableCsrfValidation = false;
}
Copy after login

The second solution is to add it to the form Hidden domain

<input name="_csrf" type="hidden" id="_csrf" value="<?= Yii::$app->request->csrfToken ?>">
Copy after login

The third solution is to add the _csrf field in AJAX

var csrfToken = $(&#39;meta[name="csrf-token"]&#39;).attr("content");
$.ajax({
  type: &#39;POST&#39;,
  url: url,
  data: {_csrf:csrfToken},
  success: success,
  dataType: dataType
});
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template