R
R
Ruslan Tilyaev2020-05-23 11:00:14
JavaScript
Ruslan Tilyaev, 2020-05-23 11:00:14

how to ajax update a widget in yii2?

Good day, I want to make receiving new notifications (in the widget) in the admin panel via ajax. Logically, I understand that you just need to update the widget after n amount of time.
My actions:
Added my widget to pjax - main.php

<!-- Header and Sidebar -->
    <?php \yii\widgets\Pjax::begin(['id' => 'pjax-container']); ?>
    <?php echo \backend\components\HeaderWidget::widget()?>
    <?php \yii\widgets\Pjax::end(); ?>


Already implemented an update in the widget after 5 seconds - header.php
//код...   менюшка + хедер

<?php
$script = <<< JS
$(document).ready(function() {
    setInterval(function(){ $.pjax.reload('#pjax-container'); }, 5000);
});
JS;
$this->registerJs($script);
?>


In the end, everything works well! Ahah, but it’s funny because now I can’t go to other pages, the url changes and the page itself doesn’t load!

The page does not load, but I loaded)) I can’t understand what the problem is????
5ec8d80b9e969983333609.jpeg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Bukharev, 2020-05-23
@evgenybuckharev

Turn off url replacement in Pjax settings

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question