Chris Illusion
Chris Illusion

Reputation: 287

Pjax reload in pjax:complete

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: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?

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

Upvotes: 1

Views: 21050

Answers (2)

Tuychiev Toir
Tuychiev Toir

Reputation: 370

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

Upvotes: 0

Double H
Double H

Reputation: 4160

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

Upvotes: 5

Related Questions