From d515068ee807efef29b6c8406171be4725d7154f Mon Sep 17 00:00:00 2001 From: jaubourg Date: Sun, 9 Jan 2011 04:53:29 +0100 Subject: [PATCH] Fixes #7868. ResponseText is now properly propagated for error callbacks. --- src/ajax.js | 5 +++++ src/ajax/xhr.js | 16 +++++++--------- test/data/errorWithText.php | 5 +++++ test/unit/ajax.js | 17 +++++++++++++++++ 4 files changed, 34 insertions(+), 9 deletions(-) create mode 100644 test/data/errorWithText.php diff --git a/src/ajax.js b/src/ajax.js index a814d80b..744476f1 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 032668f6..a2ec4a4c 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 00000000..abd87321 --- /dev/null +++ b/test/data/errorWithText.php @@ -0,0 +1,5 @@ +