Фрагмент конфига:
Код: Выделить всё
'request' => [
.................................................................
'parsers' => [
'application/json' => 'yii\web\JsonParser',
]
],
Фрагмент jscript.js:
Код: Выделить всё
$('#treeBtn').click(function() {
var data = $(this).serializeArray();
// alert(data);
$.ajax ({
type: 'post',
url: '/site/tree',
data: data,
dataType: 'json'
})
.done(function(response) {
if (response.data.success == true) {
alert("Wow you commented");
}
})
.fail(function(error) {
console.log(error);
})
});
Код: Выделить всё
public function actionTree()
{
Yii::$app->response->format = Response::FORMAT_JSON;
$items = \Yii::$app->request->post();
return $items;
// return $this->render('tree', [
// 'items' => $items,
// ]);
}