Skip to content

Commit 0ed9909

Browse files
committed
Fixes #9854: propagates native statusText onto jqXHR.statusText. statusText in callbacks is still normalized. Unit test added.
1 parent 1d220cd commit 0ed9909

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

src/ajax.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ jQuery.extend({
480480
// Callback for when everything is done
481481
// It is defined here because jslint complains if it is declared
482482
// at the end of the function (which would be more logical and readable)
483-
function done( status, statusText, responses, headers ) {
483+
function done( status, nativeStatusText, responses, headers ) {
484484

485485
// Called once
486486
if ( state === 2 ) {
@@ -508,6 +508,7 @@ jQuery.extend({
508508
var isSuccess,
509509
success,
510510
error,
511+
statusText = nativeStatusText,
511512
response = responses ? ajaxHandleResponses( s, jqXHR, responses ) : undefined,
512513
lastModified,
513514
etag;
@@ -559,7 +560,7 @@ jQuery.extend({
559560

560561
// Set data for the fake xhr object
561562
jqXHR.status = status;
562-
jqXHR.statusText = statusText;
563+
jqXHR.statusText = "" + ( nativeStatusText || statusText );
563564

564565
// Success/Error
565566
if ( isSuccess ) {

test/data/statusText.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
header( "HTTP/1.0 $_GET[status] $_GET[text]" );
4+
5+
?>

test/unit/ajax.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2092,6 +2092,19 @@ test( "jQuery.ajax - Context with circular references (#9887)", 2, function () {
20922092
ok( success, "context with circular reference did not generate an exception" );
20932093
});
20942094

2095+
test( "jQuery.ajax - statusText" , 4, function() {
2096+
stop();
2097+
jQuery.ajax( url( "data/statusText.php?status=200&text=Hello" ) ).done(function( _, statusText, jqXHR ) {
2098+
strictEqual( statusText, "success", "callback status text ok for success" );
2099+
strictEqual( jqXHR.statusText, "Hello", "jqXHR status text ok for success" );
2100+
jQuery.ajax( url( "data/statusText.php?status=404&text=World" ) ).fail(function( jqXHR, statusText ) {
2101+
strictEqual( statusText, "error", "callback status text ok for error" );
2102+
strictEqual( jqXHR.statusText, "World", "jqXHR status text ok for error" );
2103+
start();
2104+
});
2105+
});
2106+
});
2107+
20952108
test( "jQuery.ajax - statusCode" , function() {
20962109

20972110
var count = 12;

0 commit comments

Comments
 (0)