mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
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
This commit is contained in:
parent
3cad5c435a
commit
bc5f82ba1d
15
src/ajax.js
15
src/ajax.js
@ -713,8 +713,19 @@ jQuery.extend( {
|
|||||||
|
|
||||||
// Callback for when everything is done
|
// Callback for when everything is done
|
||||||
function done( status, nativeStatusText, responses, headers ) {
|
function done( status, nativeStatusText, responses, headers ) {
|
||||||
var isSuccess, success, error, response, modified,
|
var isSuccess, success, error, response, modified, statusText;
|
||||||
statusText = nativeStatusText;
|
|
||||||
|
if ( typeof status === "object" ) {
|
||||||
|
|
||||||
|
// The new, object-based API
|
||||||
|
nativeStatusText = status.statusText;
|
||||||
|
responses = status.responses;
|
||||||
|
headers = status.headers;
|
||||||
|
|
||||||
|
status = status.status;
|
||||||
|
}
|
||||||
|
|
||||||
|
statusText = nativeStatusText;
|
||||||
|
|
||||||
// Ignore repeat invocations
|
// Ignore repeat invocations
|
||||||
if ( completed ) {
|
if ( completed ) {
|
||||||
|
@ -63,23 +63,23 @@ jQuery.ajaxTransport( function( options ) {
|
|||||||
if ( type === "abort" ) {
|
if ( type === "abort" ) {
|
||||||
xhr.abort();
|
xhr.abort();
|
||||||
} else if ( type === "error" ) {
|
} else if ( type === "error" ) {
|
||||||
complete(
|
complete( {
|
||||||
|
|
||||||
// File: protocol always yields status 0; see trac-8605, trac-14207
|
// File: protocol always yields status 0; see trac-8605, trac-14207
|
||||||
xhr.status,
|
status: xhr.status,
|
||||||
xhr.statusText
|
statusText: xhr.statusText
|
||||||
);
|
} );
|
||||||
} else {
|
} else {
|
||||||
complete(
|
complete( {
|
||||||
xhrSuccessStatus[ xhr.status ] || xhr.status,
|
status: xhrSuccessStatus[ xhr.status ] || xhr.status,
|
||||||
xhr.statusText,
|
statusText: xhr.statusText,
|
||||||
|
|
||||||
// For XHR2 non-text, let the caller handle it (gh-2498)
|
// For XHR2 non-text, let the caller handle it (gh-2498)
|
||||||
( xhr.responseType || "text" ) === "text" ?
|
responses: ( xhr.responseType || "text" ) === "text" ?
|
||||||
{ text: xhr.responseText } :
|
{ text: xhr.responseText } :
|
||||||
{ binary: xhr.response },
|
{ binary: xhr.response },
|
||||||
xhr.getAllResponseHeaders()
|
headers: xhr.getAllResponseHeaders()
|
||||||
);
|
} );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user