Peter Wateber
Peter Wateber

Reputation: 3948

Prevent re-init in ajax

I have lots of page ajax request on my site. I am using jquery hashchange plugin to integrate them.

Now, as I have observed, after I do $(window).hashchange I always have to re-init some other plugins (e.g. fullcalendar, tooltip, and etc.).

I've been trying to google - on how to prevent re-init during ajax request. I've tried it using live and it works but the problem is there are certain plugins that wont need to use .live function especially when it's content-based (e.g. fullcalendar, tooltip (page load), etc.). I've been trying to solve this issue by using:

  $(window).on("hashchange")

I can test if the elements exist and RE-INIT THE PLUGINS (which is so dirty for me), and the problem: the plugins wont work/read.

What would be the best approach in initializing plugins once everytime you do it in ajax? Is that even possible?

P.S. still beginning to learn and explore more on ajax.

Upvotes: 5

Views: 233

Answers (1)

Vimal Stan
Vimal Stan

Reputation: 2005

From what I understand, you want to initialize plugins loaded via AJAX calls on your page. If that's right, you can put in your plugin initialization code in the "success" callback of your AJAX call.

You only need to add the code for the plugins that need explicit initialization.

Upvotes: 1

Related Questions