Fixes #7868. ResponseText is now properly propagated for error callbacks.
This commit is contained in:
parent
69497c3fd7
commit
d515068ee8
|
@ -464,6 +464,11 @@ jQuery.extend({
|
|||
} else { // if not success, mark it as an error
|
||||
|
||||
error = error || statusText;
|
||||
|
||||
// Set responseText if needed
|
||||
if ( response ) {
|
||||
jXHR.responseText = response;
|
||||
}
|
||||
}
|
||||
|
||||
// Set data for the fake xhr object
|
||||
|
|
|
@ -137,8 +137,7 @@ jQuery.ajax.transport( function( s , determineDataType ) {
|
|||
status
|
||||
);
|
||||
|
||||
// Guess response if needed & update datatype accordingly
|
||||
if ( status >= 200 && status < 300 ) {
|
||||
// Guess response & update dataType accordingly
|
||||
response =
|
||||
determineDataType(
|
||||
s,
|
||||
|
@ -146,7 +145,6 @@ jQuery.ajax.transport( function( s , determineDataType ) {
|
|||
xhr.responseText,
|
||||
xhr.responseXML );
|
||||
}
|
||||
}
|
||||
|
||||
// Call complete
|
||||
complete(status,statusText,response,responseHeaders);
|
||||
|
|
5
test/data/errorWithText.php
Normal file
5
test/data/errorWithText.php
Normal file
|
@ -0,0 +1,5 @@
|
|||
<?php
|
||||
|
||||
header("HTTP/1.0 400 Bad Request");
|
||||
|
||||
echo "plain text message";
|
|
@ -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() {
|
||||
|
||||
expect( 2 );
|
||||
|
|
Loading…
Reference in a new issue