title: Pjax reload in pjax:complete
body: <p>I am trying to reload <code>alerts</code> 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.</p>
  
  <p>I have the following code:</p>
  
  <pre><code>$(document).on('pjax:complete', function(event) {
          $.pjax.reload({container:"#alerts"});
  });
  </code></pre>
  
  <p>However, this sends the whole page into a never ending loop.</p>
  
  <p>Is there a way to make this work or should I not use pjax for this particular problem?</p>
  
  <p>Thank you very much.</p>
  
  <p><strong>Update</strong>
  The following code works, but I feel it is not the perfect solution:</p>
  
  <pre><code>var time = Date.now();
  $(document).on(\'pjax:complete\' , function(event) {
      if(time &lt;= 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});
      }
  });
  </code></pre>