Answer the question
In order to leave comments, you need to log in
How to properly render views without reloading on ajax request in yii2?
there is a news view in which there is a button on which a js event is hung that executes this js code
$.ajax({
type: 'POST',
data: {'sum': sum},
headers: {
'X-CSRF-Token': yii.getCsrfToken()
},
url: '/news/some-news',
dataType: 'json',
cache: false,
success: function (result) {
console.log(result)
},
error: function (jqXHR, textStatus, errorThrown) {
setShowCalls( all );
}
});
public function actionSomeNews()
{
if(!Yii::$app->request->isAjax)return;
$sum = Yii::$app->request->post('sum');
$model = News::getSomeNews($sum);
return $this->renderAjax()('some_news, [
'model' => $model,
]);
}
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