我试图在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});
}
});发布于 2015-10-26 12:58:56
在pjax的特定id上尝试Pjax如下:-
$this->registerJs('
jQuery(document).on("pjax:success", "#brand-form", function(event){
$.pjax.reload({container:"#alerts",timeout:2e3})
}
);
');发布于 2019-03-13 06:26:43
您的问题可能是使用一个URL容器将选项location添加到容器中。如果您页面上有多个pjax需要添加pjax id和location
https://stackoverflow.com/questions/33346165
复制相似问题