Answer the question
In order to leave comments, you need to log in
Yii1 Ajax request how to write?
Project on Yii1.
Did according to this example , but for some reason even the form cannot be displayed. Because it throws an error that the variable $input = $_POST['input'] is not defined. I just used it for testing purposes.
I’m doing statistics in the admin panel and I wanted to fasten the ajax select option to display for the day, month, year, all the time - I wrote the selection logic itself, working with dates and queries on the models, but I don’t know how to update via Ajax. Does anyone have a complete working example? At least to understand how it works in conjunction with yii?
on Yii2 I did in a similar way
//views
$.ajax({
url: '<?php echo Yii::$app->request->baseUrl. '/controller/Some' ?>',
type: 'post',
data: {
someValue: $("#someValue").val() ,
_csrf : '<?=Yii::$app->request->getCsrfToken()?>'
},
success: function (data) {
console.log(data.result);
}
});
//контроллер
public function actionSome()
{
if (Yii::$app->request->isAjax) {
$data = Yii::$app->request->post();
// вытаскиваем из запроса данные и выполняем логику и оформляем ответ
$result = //ответ
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
return [
'result' => $result,
'code' => 100,
];
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question