]> source.dussan.org Git - jquery.git/commitdiff
Fixes #7868. ResponseText is now properly propagated for error callbacks.
authorjaubourg <j@ubourg.net>
Sun, 9 Jan 2011 03:53:29 +0000 (04:53 +0100)
committerjaubourg <j@ubourg.net>
Sun, 9 Jan 2011 03:53:29 +0000 (04:53 +0100)
src/ajax.js
src/ajax/xhr.js
test/data/errorWithText.php [new file with mode: 0644]
test/unit/ajax.js

index a814d80bed3c8cdfc8e24380641a91cf31a7f8d7..744476f1a399f5d77bac0290861d58f21bc1b228 100644 (file)
@@ -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
index 032668f68d7e60228208b3f974600a695b50a1df..a2ec4a4c5b500d0e76e2bac35e1b9da4f3a69a84 100644 (file)
@@ -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 (file)
index 0000000..abd8732
--- /dev/null
@@ -0,0 +1,5 @@
+<?php
+
+header("HTTP/1.0 400 Bad Request");
+
+echo "plain text message";
\ No newline at end of file
index d5f2bc0cf09a9f5e3c5b656ba620b8446afefc58..adf589e1a3347f0916bd28fe2e05cda5b155dba9 100644 (file)
@@ -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 );