Skip to content

Commit 62e7f2c

Browse files
committed
Ajax: Support an alternative completeCallback API for transports
Apart from the existing API: ```js function( status, statusText, responses, headers ) {} ``` a new API is now available: ```js function( { status, statusText, responses, headers } ) {} ``` This makes it possible to add new parameters in the future without relying on their order among parameters and being able to provide them selectively. Ref gh-4405
1 parent 721744a commit 62e7f2c

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

src/ajax.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -712,8 +712,19 @@ jQuery.extend( {
712712

713713
// Callback for when everything is done
714714
function done( status, nativeStatusText, responses, headers ) {
715-
var isSuccess, success, error, response, modified,
716-
statusText = nativeStatusText;
715+
var isSuccess, success, error, response, modified, statusText;
716+
717+
if ( typeof status === "object" ) {
718+
719+
// The new, object-based API
720+
nativeStatusText = status.statusText;
721+
responses = status.responses;
722+
headers = status.headers;
723+
724+
status = status.status;
725+
}
726+
727+
statusText = nativeStatusText;
717728

718729
// Ignore repeat invocations
719730
if ( completed ) {

src/ajax/xhr.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,23 +64,23 @@ jQuery.ajaxTransport( function( options ) {
6464
if ( type === "abort" ) {
6565
xhr.abort();
6666
} else if ( type === "error" ) {
67-
complete(
67+
complete( {
6868

6969
// File: protocol always yields status 0; see #8605, #14207
70-
xhr.status,
71-
xhr.statusText
72-
);
70+
status: xhr.status,
71+
statusText: xhr.statusText
72+
} );
7373
} else {
74-
complete(
75-
xhrSuccessStatus[ xhr.status ] || xhr.status,
76-
xhr.statusText,
74+
complete( {
75+
status: xhrSuccessStatus[ xhr.status ] || xhr.status,
76+
statusText: xhr.statusText,
7777

7878
// For XHR2 non-text, let the caller handle it (gh-2498)
79-
( xhr.responseType || "text" ) === "text" ?
79+
responses: ( xhr.responseType || "text" ) === "text" ?
8080
{ text: xhr.responseText } :
8181
{ binary: xhr.response },
82-
xhr.getAllResponseHeaders()
83-
);
82+
headers: xhr.getAllResponseHeaders()
83+
} );
8484
}
8585
}
8686
};

0 commit comments

Comments
 (0)