0

How would i upgrade the solution provided in this question How can I create a "Please Wait, Loading..." animation using jQuery?

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?

Community
  • 1
  • 1
Chris Nevill
  • 5,922
  • 11
  • 44
  • 79

2 Answers2

3

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"); });
jfriend00
  • 683,504
  • 96
  • 985
  • 979
0

The second event should be ajaxComplete

$(document).ajaxComplete(function(){   $("body").removeClass("loading"); });
Starx
  • 77,474
  • 47
  • 185
  • 261