admin管理员组

文章数量:1297062

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.

I have the following code:

$(document).on('pjax:plete', 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?

Thank you very much.

Update The following code works, but I feel it is not the perfect solution:

var time = Date.now();
$(document).on(\'pjax:plete\' , 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});
    }
});

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.

I have the following code:

$(document).on('pjax:plete', 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?

Thank you very much.

Update The following code works, but I feel it is not the perfect solution:

var time = Date.now();
$(document).on(\'pjax:plete\' , 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});
    }
});
Share edited Oct 26, 2015 at 15:51 Chris Illusion asked Oct 26, 2015 at 12:47 Chris IllusionChris Illusion 2872 gold badges6 silver badges18 bronze badges 2
  • See this answer too stackoverflow./questions/27777512/… you'll need to set the timeout as well else it won't work. – Coz Commented Oct 26, 2015 at 14:07
  • I've updated the question. Quite the opposite worked. – Chris Illusion Commented Oct 26, 2015 at 16:01
Add a ment  | 

2 Answers 2

Reset to default 5

try pjax on particular id of Pjax Widget as:-

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

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

本文标签: javascriptPjax reload in pjaxcompleteStack Overflow