]> source.dussan.org Git - jquery.git/commitdiff
Fixes #9854: propagates native statusText onto jqXHR.statusText. statusText in callba...
authorjaubourg <j@ubourg.net>
Sat, 23 Jul 2011 00:39:12 +0000 (02:39 +0200)
committerjaubourg <j@ubourg.net>
Sat, 23 Jul 2011 00:39:12 +0000 (02:39 +0200)
src/ajax.js
test/data/statusText.php [new file with mode: 0644]
test/unit/ajax.js

index 7bbfaf9069299a64c13435881796e99edd1ae1e0..3b811b550080032e25a00871299edf5155d2b073 100644 (file)
@@ -480,7 +480,7 @@ jQuery.extend({
                // Callback for when everything is done
                // It is defined here because jslint complains if it is declared
                // at the end of the function (which would be more logical and readable)
-               function done( status, statusText, responses, headers ) {
+               function done( status, nativeStatusText, responses, headers ) {
 
                        // Called once
                        if ( state === 2 ) {
@@ -508,6 +508,7 @@ jQuery.extend({
                        var isSuccess,
                                success,
                                error,
+                               statusText = nativeStatusText,
                                response = responses ? ajaxHandleResponses( s, jqXHR, responses ) : undefined,
                                lastModified,
                                etag;
@@ -559,7 +560,7 @@ jQuery.extend({
 
                        // Set data for the fake xhr object
                        jqXHR.status = status;
-                       jqXHR.statusText = statusText;
+                       jqXHR.statusText = "" + ( nativeStatusText || statusText );
 
                        // Success/Error
                        if ( isSuccess ) {
diff --git a/test/data/statusText.php b/test/data/statusText.php
new file mode 100644 (file)
index 0000000..daf58ce
--- /dev/null
@@ -0,0 +1,5 @@
+<?php
+
+header( "HTTP/1.0 $_GET[status] $_GET[text]" );
+
+?>
\ No newline at end of file
index 6af56db4fa52057fa8479b4f7de4290a55402d2d..ed6acda92656a7f6cf710c018570dcae485737c5 100644 (file)
@@ -2092,6 +2092,19 @@ test( "jQuery.ajax - Context with circular references (#9887)", 2, function () {
        ok( success, "context with circular reference did not generate an exception" );
 });
 
+test( "jQuery.ajax - statusText" , 4, function() {
+       stop();
+       jQuery.ajax( url( "data/statusText.php?status=200&text=Hello" ) ).done(function( _, statusText, jqXHR ) {
+               strictEqual( statusText, "success", "callback status text ok for success" );
+               strictEqual( jqXHR.statusText, "Hello", "jqXHR status text ok for success" );
+               jQuery.ajax( url( "data/statusText.php?status=404&text=World" ) ).fail(function( jqXHR, statusText ) {
+                       strictEqual( statusText, "error", "callback status text ok for error" );
+                       strictEqual( jqXHR.statusText, "World", "jqXHR status text ok for error" );
+                       start();
+               });
+       });
+});
+
 test( "jQuery.ajax - statusCode" , function() {
 
        var count = 12;