Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 308
Peter Wateber Avatar asked Nov 12 '22 09:11

Peter Wateber


1 Answers

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.

like image 173
Vimal Stan Avatar answered Nov 15 '22 01:11

Vimal Stan