In yii2 how to call a table using ajax?

Hello! Before this I never worked with ajax. I Need when in a view when you press the button to call the table.
For this I added a table and a button in vushku
<?= GridView::widget([
 'dataProvider' => $dataProvider2,
 'filterModel' => $searchModel,

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


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

 <?= Html::a('Show characters', ['/kniga1/Hero'], ['class'=>'btn btn-primary']) ?>

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


I know that the button and the table and so is displayed in vjushke. But I need that the table was called when I press the button.
How it correctly to implement using ajax?
March 19th 20 at 09:10
1 answer
March 19th 20 at 09:12
Send an ajax request on button click on the server to generate html to js in the answer and paste in the appropriate place.
But it is possible to generate at once, hide and show on click.

Find more questions by tags Yii