Bug Tracker

Modify

Ticket #7868 (closed bug: fixed)

Opened 3 years ago

Last modified 8 months ago

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

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

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.

Change History

comment:1 Changed 3 years ago by spullara@…

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.

comment:2 Changed 3 years ago by snover

  • Status changed from new to assigned
  • Component changed from unfiled to ajax
  • Priority changed from undecided to blocker
  • Owner set to jaubourg
  • Milestone changed from 1.next to 1.5
  • Keywords regression added

comment:3 Changed 3 years ago by jaubourg

  • Status changed from assigned to closed
  • Resolution set to fixed

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

Changeset: d515068ee807efef29b6c8406171be4725d7154f

comment:4 follow-up: ↓ 5 Changed 3 years ago by 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.

comment:5 in reply to: ↑ 4 Changed 3 years ago by jitter

Replying to 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

comment:6 Changed 3 years ago by samuel.imbert@…

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

comment:7 Changed 3 years ago by samuel.imbert@…

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

comment:8 follow-up: ↓ 9 Changed 3 years ago by jaubourg

 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.

comment:9 in reply to: ↑ 8 Changed 3 years ago by samuel.imbert

Replying to 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

comment:10 Changed 3 years ago by anonymous

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.

comment:11 Changed 3 years ago by anonymous

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

comment:12 Changed 3 years ago by kyle

comment:13 Changed 8 months ago by anonymous

Has this one been fixed? I'm seeing the same issue in Chrome still...

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.