Skip to content
Advertisement

Why doesn’t the message POST

When sending data, an empty value comes in Yii2, why is that? Data post: id, name.

JS

JavaScript

PHP

JavaScript

}

Code 200, post null

Advertisement

Answer

By default the Yii reads post params from $_POST global variable. But web server only parses request of body send as application/x-www-form-urlencoded or multipart/form-data. If you send data with Content-Type: application/json they are not parsed into $_POST variable.

To force Yii parsing JSON request you have to add json parser into yiiwebRequest::$parsers property.

You can do that for example in your web.php config file:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement