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

编程入门 行业动态 更新时间:2024-10-26 20:23:11
本文介绍了当超链接不在 pjax 中时,yii2 如何使用 pjax的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

在yii2中使用pjax,就像:

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

但是如果超链接不在 <?php Pjax::begin(); 中怎么办??><?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 有 timeout 选项.如果 PJAX 在此超时期间未获得 AJAX 响应,它将执行整页重新加载.使用以下 JS 代码段:

PJAX has timeout option. If PJAX not obtain AJAX response during this timeout, it will perform full page reload. Use following JS snippet:

$.pjax.defaults.timeout = false;       // For JS use case yor should manual override default timeout.
$.pjax.reload({container: '#pjaxId'});

或更短的片段:

$.pjax.reload('#pjaxId', {timeout : false});

此外,在我的项目中,我使用了 Pjax 的覆盖版本:

Moreover in my projects I use overrided version of 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;
}

这篇关于当超链接不在 pjax 中时,yii2 如何使用 pjax的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-23 18:13:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1047546.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   中时   超链接   pjax

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!