Riko
Riko

Reputation: 131

Pjax. Other JS scripts on a page doesn't work

everyone!

I have integrated to my site a pjax. It is working but other js-scripts like GoogleMap or DataTable - no. If press f5 to reload the page - all other js on the page working perfect! What I did wrong? How to resolve this issue?

Upvotes: 1

Views: 1840

Answers (1)

Steve K
Steve K

Reputation: 9055

Pjax uses ajax to replace content so more than likely you are just loading your javascript on the document ready and you need to reload it when pjax is completed. There is a handler that you can use when pjax is completed to restart your javascript.

You can see pjax's events on the github page at https://github.com/defunkt/jquery-pjax

Scroll to the bottom and see events.

But you could probably do something like the following but it is hard to tell becaue you didn't post any code.

You could either state your funcitons and then initiate them on document ready and after pjax completes like so.

function datatables(){
  //your datatables code here
{
function googleMaps(){
  //your google maps code here
}
$( document ).ready(function() {
  datatables();
  googleMaps();
});
$(document).on('pjax:complete', function() {
  datatables();
  googleMaps();
});

Or you could state them on document ready and when pjax completes like so

$( document ).ready(function() {
  //your datatables code here
  //your google maps code here
});
$(document).on('pjax:complete', function() {
  //your datatables code here
  //your google maps code here
});

Or something to that effect.

Hope it helps.

Upvotes: 2

Related Questions