Skip to main content

Bug Tracker

Side navigation

#5968 closed bug (duplicate)

Opened January 28, 2010 06:07PM UTC

Closed June 14, 2010 12:20AM UTC

AJAX failures don't call error but rather success

Reported by: bbirnbau Owned by:
Priority: major Milestone: 1.4.2
Component: ajax Version: 1.4.1
Keywords: ajax, error, success, callback Cc:
Blocked by: Blocking:

I have observed that a failed ajax request does not properly call error upon failure. I have turned off my server and watch in firebug to see my successful requests turn to failures however the wrong events are called. Success does get called while error does not

I have confirmed that the code below works properly in jQuery 1.3.2 and is broken in 1.4.0 and 1.4.1

<script type="text/javascript">


setInterval(function() {if (ready_to_poll == true && init_tickets_to_load == 0 && polling_failures < 5) { d = new Date();ready_to_poll=false;; jQuery.ajax({complete:function(request){last_que_id=current_que_id;last_twitter_search_id=current_twitter_search_id;ready_to_poll=true; if (polling_failures == 5) { tb_show('error title','#TB_inline?height=300&width=600&inlineId=screen_pop_window&modal=true');$('#TB_ajaxContent').html('<div style="text-align:center;color:red;margin-top:80px;font-size:1.5em;padding:20px;">We are sorry but something went wrong. Please close your browser and try again...</div>');}}, data:'cqid='+current_que_id+'&lqid='+last_que_id+'&cqiids='+current_queue_items+ '&cqsoid='+current_queue_sort_order_id+'&cqpnum='+current_queue_page_num+'&cbt='+d.getTime()+'&ctsid='+current_twitter_search_id+'<sid='+last_twitter_search_id+'&ctsmaxid='+current_twitter_search_max_id + '&cvtsids='+current_viewed_tweet_search_ids + '&authenticity_token=' + encodeURIComponent(AUTH_TOKEN), dataType:'script', error:function(request){console.log('error poll');polling_failures++;}, success:function(request){console.log('success poll');polling_failures=0;}, type:'get', url:'/agent/poll'}); }}, 5 * 1000)



Attachments (1)
Change History (14)

Changed January 28, 2010 09:17PM UTC by bbirnbau comment:1

I would like to add more information that may be helpful. I've learned that on 1.4.1 when there is a 500 that comes back from the server it does fire the error callback. Where it doesn't fire the error is when it can't connect to the server

Changed January 29, 2010 02:48AM UTC by dmethvin comment:2

resolution: → invalid
status: newclosed

The error callback is called if the request times out, or if the request returns with an http error code (such as 500). The request hasn't returned (it can't reach the site apparently) so you should set a timeout.

Changed January 29, 2010 03:46PM UTC by bbirnbau comment:3

resolution: invalid
status: closedreopened

I'm not sure that we are saying the same thing here. In jQuery 1.3.2 when the server was not available error was called correctly. In jQuery 1.4.0 and 1.4.1 when an Ajax request can't reach the server it returns very quickly (no timeout is required) however the error callback is not fired and the success one is. This is not something that I can solve via a timeout and I honestly believe that when there is an error on an request (server not available) that jQuery should not ever return success.

Changed January 29, 2010 03:56PM UTC by john comment:4

Do you have more information about what error codes the server is returning? Can you give us a dump of the XHR so that we can investigate further?

Changed January 29, 2010 05:52PM UTC by bbirnbau comment:5

Please see the link to a screenshot of Firebug. The first 2 requests were fine then I turned off the server and you'll see that the next 3 have a status of TIMEOUT.

Thanks so much for looking into this as we love using jQuery and have found 1.4.1 to be much faster than 1.3.2 and don't want to have to go back to it.

Changed February 01, 2010 01:46AM UTC by bbirnbau comment:6

Changed February 04, 2010 04:31AM UTC by Joseph Crotty comment:7

Today I set up a totally stripped down test web page with one link to call .ajax(). The POST url was my localhost and I had turned the webserver off. Firebug net panel XHR shows the request Status as Timeout just like bbirnbau screen shot above. In other words the webserver will never issue anything. FF will try to use it and issue an immediate Timeout as it is unavailable.

IE6-8 call the error: callback function with the textStatus value of 'error' and an XHR object. Chrome, FF, and Safari call the success: callback function with the textStatus value of 'success' and an empty XHR object.

Changed February 21, 2010 12:11AM UTC by ris comment:8

I'm getting the same results as Joseph Crotty in jQuery 1.4.1 and 1.4.2 on Iceweasel (Firefox) 3.0.6

Everything causes a 'success', even calling abort() on the xhr.

Is this perhaps related to ticket #6060 ?

Changed March 05, 2010 12:09PM UTC by peterl comment:9

I have the same problems, using firefox 3.6 and safari 4.0.

I've created the following test case:

<script type="text/javascript" src="jquery-1.4.2.js"></script>
<button id="test">Click here to test</button>
$("#test").click(function() {
    var p = {};
    p.error = function() {
	alert("Error message");
    p.success = function(rdata, status){
	alert("DATA: " + rdata + " -- " + status);
    p.cache = false;
    p.type = "GET";
    p.url = "data.txt";

Create a file data.txt with a text in it. Start the webserver, click the button; it will give you the text with DATA: in front of it. Stop the webserver, so there is an connection refused, then click the button: it will still say DATA: which is proof the success callback is called, while it should not.

Change the script to use jquery 1.3.2 instead of 1.4.2 to get the expected results: with jquery 1.3.2 the error callback is called when your http server is shut down....

Changed March 07, 2010 02:46PM UTC by ris comment:10

Having done a bit more work with this, I would have to say this error is rather erratic. On some of my $.ajax requests this problem occurs, and the success function is called with a null data value. On other requests, everything works as it should.

I haven't yet managed to narrow down the problem cases.

Changed March 09, 2010 07:46PM UTC by maqdev comment:11

There is many duplicate tickets with this problem, here is the one that contains a fix that should help I guess:

Changed March 09, 2010 10:09PM UTC by peterl comment:12

I've tried the patch from ticket:6060 but it did not work. I assume that this particular problem is not related to that ticket...

Changed June 09, 2010 01:09AM UTC by nic_bellamy comment:13

This all appears to be related to changeset c3c94823f27ee1e935586d46fd86f055f3a3d97d that added handling for an Opera bug with 304 "Not Modified" responses.

Uploading a "works for me" patch that uses browser sniffing to only apply the 304 workaround when using Opera, so it doesn't break all the other browsers handling of refused connections.

See 0001-Fix-jQuery.ajax-success-function-being-called-when-H.patch attachment

Changed June 14, 2010 12:20AM UTC by dmethvin comment:14

resolution: → duplicate
status: reopenedclosed

Merging all to dup #6060.