Pjax在pjax中重新加载:完成

问题描述 投票:1回答:2

我想在pjax请求后重新加载alerts容器。我的目标是在任何pjax请求发出后重新加载容器的代码,所以我不必每次都单独调用它。

我有以下代码:

$(document).on('pjax:complete', function(event) {
        $.pjax.reload({container:"#alerts"});
});

但是,这会将整个页面发送到一个永无止境的循环。

有没有办法使这项工作或我不应该使用pjax这个特定的问题?

非常感谢你。

更新以下代码有效,但我觉得它不是完美的解决方案:

var time = Date.now();
$(document).on(\'pjax:complete\' , function(event) {
    if(time <= Date.now()){ //Check if there has been a recent reload
        time = Date.now() + 1000;
        console.log(time);
        App.restartGlobalFunction();
        $.pjax.reload({container:"#alerts", async:false});
    }
});
javascript yii2 pjax
2个回答
3
投票

在Pjax Widget的特定id上尝试pjax: -

$this->registerJs('
    jQuery(document).on("pjax:success", "#brand-form",  function(event){
            $.pjax.reload({container:"#alerts",timeout:2e3})
          }
        );
   ');

0
投票

你问题可能是采取url pjax容器添加选项location采取容器。如果您页面许多pjax需要添加pjax idlocation

© www.soinside.com 2019 - 2024. All rights reserved.