D
D
DoNetSSS2015-10-28 17:27:40
Yii
DoNetSSS, 2015-10-28 17:27:40

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(); ?>

Controller
public function actionTime()
    {
        return $this->render('auto', ['time' => date('H:i:s')]);
    }

vive index.php
<?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

2 answer(s)
L
Lumore, 2015-10-28
@Lumore

public function actionTime()
    {
        return $this->renderAjax('auto', ['time' => date('H:i:s')]);
    }

A
alex5e, 2015-11-01
@alex5e

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 question

Ask a Question

731 491 924 answers to any question