在 yii2 中使用 pjax,就像:
<?php Pjax::begin(); ?>
<?= Html::a("Refresh", ['site/index'], ['class' => 'btn btn-lg btn-primary']);?>
<h1>Current time: <?= $time ?></h1>
<?php Pjax::end(); ?>
但如果超链接不在<?php Pjax::begin(); ?> <?php Pjax::end(); ?>
, 就像:
<nav>
<a href="">Click to refresh</a>
</nav>
<?php Pjax::begin(); ?>
<h1>Current time: <?= $time ?></h1>
<?php Pjax::end(); ?>
PJAX 有timeout
选项。如果PJAX在此超时期间没有获得AJAX响应,它将执行整页重新加载。
使用以下 JS 片段:
$.pjax.defaults.timeout = false; // For JS use case yor should manual override default timeout.
$.pjax.reload({container: '#pjaxId'});
或更短的片段:
$.pjax.reload('#pjaxId', {timeout : false});
此外,在我的项目中,我使用 Pjax 的重写版本:
/**
* Custom Pjax with incremented timeout.
* JS for Pjax updating:
* <code>
* $.pjax.defaults.timeout = false; // For JS use case yor should manual override default timeout.
* $.pjax.reload({container: '#pjaxId'});
*
* // OR
* $.pjax.reload('#pjaxId', {timeout : false});
*
* // OR for gridview with search filters
* $('.grid-view').yiiGridView('applyFilter'); // Thats true only if you have search Filters
* </code>
*
* Note: In more cases ID of widget should be static, because widgetId is autoincremented and browser version of page may be not up-to-date.
*/
class Pjax extends \yii\widgets\Pjax
{
/**
* @var int Timeout {@link \yii\widgets\Pjax::$timeout}.
* For JS use case yor should manual override defaults ( $.pjax.defaults.timeout = false; ).
*/
public $timeout = 30000;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)