Skip to main content

Bug Tracker

Side navigation

#7868 closed bug (fixed)

Opened December 30, 2010 05:40AM UTC

Closed January 09, 2011 05:24AM UTC

Last modified October 03, 2011 03:14PM UTC

AJAX error handler doesn't get access to the responseText, regression

Reported by: spullara@yahoo.com Owned by: jaubourg
Priority: blocker Milestone: 1.5
Component: ajax Version: git
Keywords: regression Cc:
Blocked by: Blocking:
Description

In 1.4.2 I get an error callback on a 400 that includes the xhr with a populated responseText that I can parse and display as an error. In GIT the responseText is filtered out early on in the error handling code at a higher level and is not passed down to the error handler.

For example:

  api.followbag = function(p, follower, following, success, failure) {
    var z = p.crumb, r = p.render;
    $.ajax({
      url: '/v1/follow/' + follower + '/follows/bag/' + following + '?crumb=' + z + '' + (r ? '&render=' + r : '') + '',
      type: 'POST',
      dataType: "json",
      success: function(d) {
        if (success) success(d);
      },
      error: function(xhr) {
        if (failure) failure($.parseJSON(xhr.responseText));
      }
    });
  };

The error function doesn't get passed the responseText and therefore cannot pass on the error information to the rest of the program.

Attachments (0)
Change History (11)

Changed December 30, 2010 05:45AM UTC by spullara@yahoo.com comment:1

I'm pretty sure this is the offending code:

lines 7261-7269

                            // Guess response if needed & update datatype accordingly
                            if ( status >= 200 && status < 300 ) {
                                response = 
                                    determineDataType(
                                        s,
                                        xhr.getResponseHeader("content-type"),
                                        xhr.responseText,
                                        xhr.responseXML );
                            }

I have no idea why it is filtering out the data and not passing it on to the handler.

Changed December 31, 2010 06:13PM UTC by snover comment:2

component: unfiledajax
keywords: → regression
milestone: 1.next1.5
owner: → jaubourg
priority: undecidedblocker
status: newassigned

Changed January 09, 2011 05:24AM UTC by jaubourg comment:3

resolution: → fixed
status: assignedclosed

Fixes #7868. ResponseText is now properly propagated for error callbacks.

Changeset: d515068ee807efef29b6c8406171be4725d7154f

Changed February 17, 2011 04:30PM UTC by luke.biddell@gmail.com comment:4

Guys,

I'm running jquery 1.5 and I'm seeing this issue. I have jq talking to jersey jax-rs and if I return json from jersey with an http 400, xhr.responseText is empty. If I return the same json from jersey with a 200, xhr.responseText is present and correct.

I've tested in firefox and chrome and the behaviour is the same.

I've also tested the http call using curl and from curl I can see the response body.

Changed February 17, 2011 05:03PM UTC by jitter comment:5

Replying to [comment:4 luke.biddell@…]:

Guys, I'm running jquery 1.5 and I'm seeing this issue. I have jq talking to jersey jax-rs and if I return json from jersey with an http 400, xhr.responseText is empty. If I return the same json from jersey with a 200, xhr.responseText is present and correct. I've tested in firefox and chrome and the behaviour is the same. I've also tested the http call using curl and from curl I can see the response body.

Please submit a reduced test case, which reproduces the issue you are experiencing, on http://jsfiddle.net. So that we can investigate this issue further. Also make sure to read the link given below, in order to provide a most useful bug report.


How to report bugs

Changed September 15, 2011 01:45PM UTC by samuel.imbert@gmail.com comment:6

i'm experiencing the same issue with jquery 1.5.

Can you explain how did you fixed this bug and how to use the responseText when 400 error code is send ?

Thanks

Changed September 15, 2011 01:51PM UTC by samuel.imbert@gmail.com comment:7

Here is my example : http://jsfiddle.net/x4F3f/

Changed September 15, 2011 02:03PM UTC by jaubourg comment:8

http://jsfiddle.net/RTvQQ/ is working in chrome.

My only guess is that you're trying on a browser that does not support cross-domain requests.

Changed September 15, 2011 04:57PM UTC by samuel.imbert comment:9

Replying to [comment:8 jaubourg]:

My only guess is that you're trying on a browser that does not support cross-domain requests.

it's working for the success 200 status code but not in errors.

i'm using Mozilla firefox 3.6.22 for Ubuntu

Changed October 01, 2011 08:02PM UTC by anonymous comment:10

I have the same problem - when the response code is 400, xhr.responseText is empty on Firefox 3.6.23. In chrome this works fine. FF 3.6 does support cross domain requests.

If i change response code to 200, xhr.responseText is not empty on FF 3.6.

Changed October 03, 2011 03:14PM UTC by anonymous comment:11

in firefox 3.6 xhr.status is not populated when http response is 400. In chrome xhr.status is populated when 400.