Ticket #11607 (closed bug: invalid)
$.ajax success event not working
| Reported by: | fistandanbitus@… | Owned by: | fistandanbitus@… |
|---|---|---|---|
| Priority: | undecided | Milestone: | None |
| Component: | unfiled | Version: | 1.7.2 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
I was using jquery 1.6 and decides to upgrade to 1.7.2, but then i noticed some ajax process weren't working properly.
I noticed that the "success" event wasn't firing up. I even put a simple "alert(1)" right after the event code like so "success:function(data){ alert(1) }" but it didn't work. Even $.getJSON didn't work.
After some serious debugging session, I concluded that the 1.7.2 versions was to blame, I downgraded back to 1.6 and everything is back to normal.
Change History
comment:1 Changed 14 months ago by rwaldron
- Owner set to fistandanbitus@…
- Status changed from new to pending
comment:2 Changed 14 months ago by trac-o-bot
- Status changed from pending to closed
- Resolution set to invalid
Because we get so many tickets, we often need to return them to the initial reporter for more information. If that person does not reply within 14 days, the ticket will automatically be closed, and that has happened in this case. If you still are interested in pursuing this issue, feel free to add a comment with the requested information and we will be happy to reopen the ticket if it is still valid. Thanks!
comment:3 Changed 13 months ago by jquery@…
I'm seeing this too in 1.7.2. My code is a BBoM and so providing a stripped-down example is challenging.
However, I will add that one of the interesting properties of this bug that I've noticed is that in my specific situation, this works:
$.ajax({success: function(){ /* code runs */ }});
However, this does not:
$.ajax({}).success(function(){ /* code doesn't run */ });
And yet, and this is the oddest part, using a mix of styles will cause *both* to fire (even the one that wasn't previously):
$.ajax({success: function(){ /* code runs */ }}).success(function(){ /* code runs */ });
Some more info:
- my tests have been constrained to IE
- doesn't appear to affect all uses (just specific use-cases)
- the response is very large, taking 20s and almost 4mb in size
- When .success() fails to fire, IE's dev tools shows 200 OK (with the valid response body)
- Also when .success() fails to fire, .done() doesn't fire either.
comment:4 Changed 13 months ago by anonymous
Figured out the problem and have deduced a valid test case, and it appears to be caused by the [undocumented?] fact by setting a success callback within the ajaxOptions will replace any callbacks previously set via $.ajaxSetup(). However, using xhr.success(fn(){}) to set a callback merely adds to the stack. I couldn't find this distinction on http://api.jquery.com/jQuery.ajax/ but then again, it's a mountain of text and I didn't read anywhere near all of it. Just making a note here for others that may come across this in the future.
In my case, I had forgotten that I had a success callback already set with ajaxSetup(), and an exception generated in that default handler prevented any additional handlers from getting called. This explains why setting a success callback explicitly on the ajaxOptions allowed both to fire -- the original handler which generated the exception was replaced.
Here's a jsfiddle which exhibits the behavior:
And now the counterpart (overriding the default handler which generates the exception):
Repro'd on Chrome 19.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

Thanks for taking the time to contribute to the jQuery project! Please provide a complete reduced test case on jsFiddle to help us assess your ticket!
Additionally, be sure to test against the "jQuery (edge)" version to ensure the issue still exists. To get you started, use this boilerplate: http://jsfiddle.net/FrKyN/ Open the link and click to "Fork" (in the top menu) to begin.