Skip to content

Commit

Permalink
Fixes #7868. ResponseText is now properly propagated for error callba…
Browse files Browse the repository at this point in the history
…cks.
  • Loading branch information
jaubourg committed Jan 9, 2011
1 parent 69497c3 commit d515068
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 9 deletions.
5 changes: 5 additions & 0 deletions src/ajax.js
Expand Up @@ -464,6 +464,11 @@ jQuery.extend({
} else { // if not success, mark it as an error } else { // if not success, mark it as an error


error = error || statusText; error = error || statusText;

// Set responseText if needed
if ( response ) {
jXHR.responseText = response;
}
} }


// Set data for the fake xhr object // Set data for the fake xhr object
Expand Down
16 changes: 7 additions & 9 deletions src/ajax/xhr.js
Expand Up @@ -137,15 +137,13 @@ jQuery.ajax.transport( function( s , determineDataType ) {
status status
); );


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


// Call complete // Call complete
Expand Down
5 changes: 5 additions & 0 deletions test/data/errorWithText.php
@@ -0,0 +1,5 @@
<?php

header("HTTP/1.0 400 Bad Request");

echo "plain text message";
17 changes: 17 additions & 0 deletions test/unit/ajax.js
Expand Up @@ -240,6 +240,23 @@ test("jQuery.ajax() - error callbacks", function() {
}); });
}); });


test("jQuery.ajax() - responseText on error", function() {

expect( 1 );

stop();

jQuery.ajax({
url: url("data/errorWithText.php"),
error: function(xhr) {
strictEqual( xhr.responseText , "plain text message" , "Test jXHR.responseText is filled for HTTP errors" );
},
complete: function() {
start();
}
});
});

test(".ajax() - headers" , function() { test(".ajax() - headers" , function() {


expect( 2 ); expect( 2 );
Expand Down

0 comments on commit d515068

Please sign in to comment.