Answer the question
In order to leave comments, you need to log in
pjax yii2 reload page?
auto.php
<?php
use yii\helpers\Html;
use yii\widgets\Pjax;
?>
<?php Pjax::begin(); ?>
<?= Html::a("Обновить", ['/time'], ['class' => 'btn btn-lg btn-primary']);?>
<h1>Сейчас: <?= $time ?></h1>
<?php Pjax::end(); ?>
public function actionTime()
{
return $this->render('auto', ['time' => date('H:i:s')]);
}
<?php Pjax::begin(); ?>
<?= $this->render('auto', ['time' => date('H:i:s')]) ?>
<?php Pjax::end(); ?>
Answer the question
In order to leave comments, you need to log in
public function actionTime()
{
return $this->renderAjax('auto', ['time' => date('H:i:s')]);
}
The fact is that in the jquery.pjax.js file, the enable() function specifies a timeout of 650mc. Your Pjax request does not fit into this timeout, which is why the page is refreshed. The timeout can be set in Pjax::begin(), but personally it did not work for me, so I redefined the Pjax widget and already set the timeout I needed in it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question