Skip to content
Permalink
Browse files

Fixes #7868. ResponseText is now properly propagated for error callba…

…cks.
  • Loading branch information
jaubourg committed Jan 9, 2011
1 parent 69497c3 commit d515068ee807efef29b6c8406171be4725d7154f
Showing with 34 additions and 9 deletions.
  1. +5 −0 src/ajax.js
  2. +7 −9 src/ajax/xhr.js
  3. +5 −0 test/data/errorWithText.php
  4. +17 −0 test/unit/ajax.js
@@ -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,15 +137,13 @@ jQuery.ajax.transport( function( s , determineDataType ) {
status
);

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

// Call complete
@@ -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 );

0 comments on commit d515068

Please sign in to comment.
You can’t perform that action at this time.