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

Commit dc6880a

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 8969732 commit dc6880a

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
@@ -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)