March 27, 2013

Ajax Animation JQuery 1.9.2

Question by Chris Nevill

How would i upgrade the solution provided in this question
jQuery "Please Wait, Loading…" animation?

to work with JQuery 1.9.2?

I can’t seem to get it to work.
I’ve tried the following
http://jsfiddle.net/VpDUG/2485/

$(document).ajaxStart(function(){   $("body").addClass("loading"); });
$(document).ajaxStart(function(){   $("body").removeClass("loading"); });

but that hasn’t worked?

Answer by jfriend00

I think you meant to do this (using ajaxStop() for the second one):

$(document).ajaxStart(function(){   $("body").addClass("loading"); });
$(document).ajaxStop(function(){   $("body").removeClass("loading"); });

See it working here on a modified version of your jsFiddle: http://jsfiddle.net/jfriend00/gk3RL/


Also, a little more efficient to use document.body instead of "body":

$(document).ajaxStart(function(){   $(document.body).addClass("loading"); });
$(document).ajaxStop(function(){   $(document.body).removeClass("loading"); });

Answer by Starx

The second event should be ajaxComplete

$(document).ajaxComplete(function(){   $("body").removeClass("loading"); });

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!