A
A
AlexAll2020-04-18 16:45:48
Yii
AlexAll, 2020-04-18 16:45:48

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 );
            }
        });


This request refers to this action
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,
        ]);

    }


How to display the some_news view in the news view on button click without reloading?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question