Answer the question
In order to leave comments, you need to log in
Empty post yii2, what?
What's wrong with this framework?!
I am sending a js array containing several numbers to the server in a Yii2 controller. The result is an empty $_POST. Moreover, the same code works fine on another site.
var xhr = new XMLHttpRequest();
xhr.open('POST', action, true);
xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
xhr.send(data);
xhr.onloadend = function() {
console.log(xhr.response);
}
public function actionActivate()
{
Yii::$app->response->format = Response::FORMAT_JSON;
return Yii::$app->request->post();
}
Answer the question
In order to leave comments, you need to log in
you must specify in the settings
'components' => [
'request' => [
'parsers' => [
'application/json' => \yii\web\JsonParser::class,
]
],
]
$_POST gets something that can be parsed, so look in php://input
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question