Web Development. Client Satisfaction. Web Consultancy. Professional. UX. Fast. Responsive Design. Dynamic. Interactive. Innovative. Ecommerce. Wordpress plugins. Prestashop modules. You name it.

How To Detect When Ajax Finished

How To Detect When Ajax Finished

In this tutorial I will show you how to detect when ajax finished, why you should know when this event is over? Sometimes you need to call other functions which must be used on certain pages or should be fired when a class is found on the HTML. To have more control over the elements you can use this feature and every time when an ajax finished you can pass your verification and do something if the verification is passed.

For instance if you have a full ajax website and you have to init a jquery calendar but only on events page you can use this function the below:

jQuery(document).on('ajaxComplete', function(){
    if(jQuery('body').hasClass('events')){
      doSomething();
    }
});

Is quite easy to understang how to use this function and is very useful because all your verifications now will stay on single event. Here you can check all elements on the page and from here you will know what you should do with your content. The function is tested and it is working on all browsers. Anyway the above function is just an example you can pass there any verification you need, because the ajaxComplete function will fire right after the ajax is done. 

Leave a Reply

avatar
  Subscribe  
Notify of