最新消息: 新版网站上线了!!!

yii2 pajax自动刷新的例子

views\site\auto-refresh.php:
<?php
$script = <<< JS
$(document).ready(function() {
    setInterval(function(){ $("#refreshButton").click(); }, 3000);
});
JS;
$this->registerJs($script);
?>
<?php Pjax::begin(); ?>
<?= Html::a("Refresh", ['site/auto-refresh'], ['class' => 'btn btn-lg btn-primary', 'id' => 'refreshButton']) ?>
<h1>Current time: <?= $time ?></h1>
<?php Pjax::end(); ?>

controllers\SiteController.php:
public function actionAutoRefresh()
{
    return $this->render('auto-refresh', ['time' => date('H:i:s')]);
}

转载请注明:谷谷点程序 » yii2 pajax自动刷新的例子