接收json或者xml数据
yii2用ajax以post方式传递json格式的数据,需要使用下面的插件
-
下载插件 composer.json文件require部分添加
add "bobchengbin/yii2-xml-request-parser": "*"
-
执行命令
composer update
- 配置
'components' => [ 'request' => 'cookieValidationKey' => 'arsenal', 'parsers' => [ 'text/xml' => 'bobchengbin\Yii2XmlRequestParser\XmlRequestParser', 'application/xml' => 'bobchengbin\Yii2XmlRequestParser\XmlRequestParser', 'application/json' => 'yii\web\JsonParser', 'text/json' => 'yii\web\JsonParser', ], ], ... ]