There is a product card, by clicking on the order of which I transmit ajax request to the controller action, where I want to process data. But ajax in any case returns the entire page.
Button handler:
$script = <<< JS $('#createOrder').on("click", function(){ var size = $('#size').val(); var color = $('#color').val(); var id_product = $(this).data('id'); var count = $('#counter').val(); $.ajax({ type : "GET", url: "../web/index.php?r=site/create-order", data: { id_product: id_product, count: count, color: color, size: size }, success: function (data) { console.log(data); } }) }); JS; $this->registerJs($script, yii\web\View::POS_READY); Controller action:
public function actionCreateOrder() { if (Yii::$app->request->isAjax) { return 'TEST'; } } But the page generated by actionIndex is returned:
public function actionIndex() { $products = Products::getDiscounts(); return $this->render('index', compact('products')); }