Yii 2.0 ajax request CSRF validate fail
In recent Yii 2.0 dev, I found the ajax request always get csrf validate fail feedback, the error message is
Bad Request (#400)
Unable to verify your data submission.
After test, I found the problem is csrf cookies not set correct, I still get this kind error after config Yii::$app->request->csrfParam and Yii::$app->request->csrfToken. How To Setting CSRF Params
After more debug, I found the problem is because view render code in Controller. Demo Code:
//Correct
return $this->render()
//Wrong
echo $this->render()
It's working again after switch back to return.
Leave Comment