Within a data grid view, there is a text input field where I intend to trigger a controller function when the field is updated. To achieve this, I have embedded a script in my form and set up a controller function.
$this->registerJs(
"$('#product_qty').on('click', function() {
alert('Button clicked!');
$.ajax({
url: '".Yii::$app->request->baseUrl . '/suppliers_orders/changequantity' . "',
type: 'post',
data: {
id: '5' ,
_csrf : '" . Yii::$app->request->getCsrfToken() . "'
},
success: function (data) {
console.log(data.search);
},
});
});",
\yii\web\View::POS_READY,
'my-button-handler'
);
An alert message will be displayed saying 'Button clicked' when the button is clicked. However, nothing further occurs.
The Suppliers_orderController function for handling the quantity change is as follows:
public function actionChangequantity(){
if (Yii::$app->request->isAjax) {
$data = Yii::$app->request->post();
$id = $data['id'];
}
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
return [
'search' => $id,
];
}
In addition, I am attempting to trace the activity using PhpStorm and Xdebug, but the debugging process does not halt at the initial breakpoint within the controller. Could there be something missing or an issue with my JS function?