gpt4 book ai didi

php - yii2 当超链接不在 pjax 中时如何使用 pjax

转载 作者:搜寻专家 更新时间:2023-10-31 21:02:33 32 4
gpt4 key购买 nike

在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;
}

关于php - yii2 当超链接不在 pjax 中时如何使用 pjax,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39139958/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com