javascript 在 pjax:complete 中重新加载 Pjax
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33346165/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Pjax reload in pjax:complete
提问by Chris Illusion
I am trying to reload alerts
container after a pjax request.
What I am aiming for is a code that will reload the container after any pjax request has been made, so I don't have to individually call it every time.
我正在尝试alerts
在 pjax 请求后重新加载容器。我的目标是在发出任何 pjax 请求后重新加载容器的代码,因此我不必每次都单独调用它。
I have the following code:
我有以下代码:
$(document).on('pjax:complete', function(event) {
$.pjax.reload({container:"#alerts"});
});
However, this sends the whole page into a never ending loop.
但是,这会将整个页面发送到永无止境的循环中。
Is there a way to make this work or should I not use pjax for this particular problem?
有没有办法让这个工作或者我不应该使用 pjax 来解决这个特定的问题?
Thank you very much.
非常感谢你。
UpdateThe following code works, but I feel it is not the perfect solution:
更新以下代码有效,但我觉得这不是完美的解决方案:
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});
}
});
回答by Double H
try pjax on particular id of Pjax Widget as:-
在 Pjax Widget 的特定 id 上尝试 pjax 为:-
$this->registerJs('
jQuery(document).on("pjax:success", "#brand-form", function(event){
$.pjax.reload({container:"#alerts",timeout:2e3})
}
);
');
回答by Ttheitroad427
Your problem may be taking a URL pjax container to add the option location
to taking containers. if you page many one pjax to need to add pjax id
and location
您的问题可能是使用 URL pjax 容器来添加使用容器的选项location
。如果你分页很多 pjax 需要添加 pjaxid
和location