To use pjax in yii2, just like:
<?php Pjax::begin(); ?>
<?= Html::a("Refresh", ['site/index'], ['class' => 'btn btn-lg btn-primary']);?>
<h1>Current time: <?= $time ?></h1>
<?php Pjax::end(); ?>
but what if the hyperlink is not in the <?php Pjax::begin(); ?> <?php Pjax::end(); ?>
, just like:
<nav>
<a href="">Click to refresh</a>
</nav>
<?php Pjax::begin(); ?>
<h1>Current time: <?= $time ?></h1>
<?php Pjax::end(); ?>
PJAX has
timeout
option. If PJAX not obtain AJAX response during this timeout, it will perform full page reload. Use following JS snippet:or more short snippet:
Moreover in my projects I use overrided version of Pjax:
Just like this:
it worked!
I think this can solve your problem.