Why doesn’t my jQuery code add and later remove loading class?
$('#crop').click(function (ev) {
ev.preventDefault()
$.post('frame.php?action=crop', dimensions, function (json) {
$('body').addClass('loading')
picture()
}, 'json')
$('body').removeClass('loading')
})
Chrome and Firebug consoles are empty, so there shouldn’t be any errors.
jQuery version is 1.4.4
What it does is remove and then later add the class.
You’re adding the class in the callback to
$.post(), which will happen long after the subsequent removal of the class. If you swap those lines (do the add after the$.post()call and the remove in the callback) then it’ll be closer to what you want.