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. 

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x