I
I
ITwoolf2019-03-29 14:08:38
Yii
ITwoolf, 2019-03-29 14:08:38

How to call a table using ajax in yii2?

Hello! Never worked with ajax before. It is necessary for me at in a view at pushing the button to cause the table.
To do this, I added a table and a button to the view

<?= GridView::widget([
        'dataProvider' => $dataProvider2,
        'filterModel' => $searchModel,


        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

            'id',
            'name',
            'description',
            'image',
            'creation_date',
            'date_of_change',

            ['class' => 'yii\grid\ActionColumn'],
        ],
    ]); ?>

    <?= Html::a('Показать героев', ['/kniga1/Hero'], ['class'=>'btn btn-primary']) ?>

In the controller, I created an action for this button
public function actionHero (){

    }

I know that both the button and the table are already displayed in the view. But I need the table to be called when I click on the button.
What is the right way to do this with ajax?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2019-05-05
@webinar

Send an ajax request when clicking on the button, generate html on the server, get it in js in the response and paste it in the right place.
But you can generate immediately, hide and show on click.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question