🌐 AI搜索 & 代理 主页
Skip to content

Commit c27a3b8

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 jquerygh-4405
1 parent bd6b453 commit c27a3b8

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
@@ -713,8 +713,19 @@ jQuery.extend( {
713713

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

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

���src/ajax/xhr.js

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

6868
// File: protocol always yields status 0; see trac-8605, trac-14207
69-
xhr.status,
70-
xhr.statusText
71-
);
69+
status: xhr.status,
70+
statusText: xhr.statusText
71+
} );
7272
} else {
73-
complete(
74-
xhrSuccessStatus[ xhr.status ] || xhr.status,
75-
xhr.statusText,
73+
complete( {
74+
status: xhrSuccessStatus[ xhr.status ] || xhr.status,
75+
statusText: xhr.statusText,
7676

7777
// For XHR2 non-text, let the caller handle it (gh-2498)
78-
( xhr.responseType || "text" ) === "text" ?
78+
responses: ( xhr.responseType || "text" ) === "text" ?
7979
{ text: xhr.responseText } :
8080
{ binary: xhr.response },
81-
xhr.getAllResponseHeaders()
82-
);
81+
headers: xhr.getAllResponseHeaders()
82+
} );
8383
}
8484
}
8585
};

0 commit comments

Comments
 (0)