diff options
-rw-r--r-- | src/ajax.js | 5 | ||||
-rw-r--r-- | src/ajax/xhr.js | 16 | ||||
-rw-r--r-- | test/data/errorWithText.php | 5 | ||||
-rw-r--r-- | test/unit/ajax.js | 17 |
4 files changed, 34 insertions, 9 deletions
diff --git a/src/ajax.js b/src/ajax.js index a814d80be..744476f1a 100644 --- a/src/ajax.js +++ b/src/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 diff --git a/src/ajax/xhr.js b/src/ajax/xhr.js index 032668f68..a2ec4a4c5 100644 --- a/src/ajax/xhr.js +++ b/src/ajax/xhr.js @@ -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 diff --git a/test/data/errorWithText.php b/test/data/errorWithText.php new file mode 100644 index 000000000..abd873217 --- /dev/null +++ b/test/data/errorWithText.php @@ -0,0 +1,5 @@ +<?php + +header("HTTP/1.0 400 Bad Request"); + +echo "plain text message";
\ No newline at end of file diff --git a/test/unit/ajax.js b/test/unit/ajax.js index d5f2bc0cf..adf589e1a 100644 --- a/test/unit/ajax.js +++ b/test/unit/ajax.js @@ -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 ); |