yii2 how to use pjax when hyperlink is not in pjax

后端 未结 3 880
名媛妹妹
名媛妹妹 2021-01-21 09:09

To use pjax in yii2, just like:


 \'btn btn-lg btn-primary\']);?>
&         


        
3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-21 09:47

    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'});
    

    or more short snippet:

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

    Moreover in my projects I use overrided version of Pjax:

    /**
     * Custom Pjax with incremented timeout.
     * JS for Pjax updating:
     *  
     *      $.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
     *  
     *
     * 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;
    }
    

提交回复
热议问题