Skip to main content

Bug Tracker

Side navigation

#13680 closed bug (notabug)

Opened March 27, 2013 03:48PM UTC

Closed March 27, 2013 04:03PM UTC

Last modified March 27, 2013 05:28PM UTC

ajaxStart and ajaxStop no longer gets fired if error in ajax success/error callbacks

Reported by: Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.9.1
Keywords: Cc:
Blocked by: Blocking:

In our application, we have a global loading animation which blocks during ajax requests. However, if there is a javascript exception in the ajax success/error callbacks, the animation no longer gets triggered.

I wrote a test case to illustrate the problem.



Attachments (0)
Change History (3)

Changed March 27, 2013 04:03PM UTC by jaubourg comment:1

resolution: → notabug
status: newclosed

You should handle exceptions in your callbacks. jQuery will halt whenever an unhandled exception bubbles up which makes it much easier to spot bugs in applications.

You could also use a prefilter rather than ajaxStart and ajaxStop:

$.ajaxPrefilter(function( options, _, jqXHR ) {
    jqXHR.always( stopAnimation );

Changed March 27, 2013 04:41PM UTC by anonymous comment:2

We always stop animation, but why is it that the global ajax start/stop no longer get fired after an exception? Shouldn't they continue to work afterwards on subsequent calls?

Changed March 27, 2013 05:28PM UTC by jaubourg comment:3

It's because we have a global counter that is not properly reset to 0 because the exception bubbled. One of the reasons why I always tell people to prefer prefilters whenever applicable. ajaxStart and ajaxStop take concurrent requests into account, a feature that is actually rarely useful and can easily be handled by a prefilter using a simple counter.

You could try and reset to 0 but I'm not sure that's a road you want to get down to.