transport.abort( finalText );
deferred.promise( jqXHR );
// Add protocol if not provided (prefilters might expect it)
// Handle falsy url in the settings object (#10093: consistency with old signature)
// We also use the url parameter if available
s.url = ( ( url || s.url || location.href ) + "" )
.replace( rprotocol, location.protocol + "//" );
// Alias method option to type as per ticket #12004
s.type = options.method || options.type || s.method || s.type;
// Extract dataTypes list
s.dataTypes = ( s.dataType || "*" ).toLowerCase().match( rnothtmlwhite ) || [ "" ];
// A cross-domain request is in order when the origin doesn't match the current origin.
if ( s.crossDomain == null ) {
urlAnchor = document.createElement( "a" );
// Support: IE <=8 - 11, Edge 12 - 15
// IE throws exception on accessing the href property if url is malformed,
// e.g. http://example.com:80x/
// Support: IE <=8 - 11 only
// Anchor's host property isn't correctly set when s.url is relative
urlAnchor.href = urlAnchor.href;
s.crossDomain = originAnchor.protocol + "//" + originAnchor.host !==
urlAnchor.protocol + "//" + urlAnchor.host;
// If there is an error parsing the URL, assume it is crossDomain,
// it can be rejected by the transport if it is invalid
// Convert data if not already a string
if ( s.data && s.processData && typeof s.data !== "string" ) {
s.data = jQuery.param( s.data, s.traditional );
inspectPrefiltersOrTransports( prefilters, s, options, jqXHR );
// If request was aborted inside a prefilter, stop there
// We can fire global events as of now if asked to
// Don't fire events if jQuery.event is undefined in an AMD-usage scenario (#15118)
fireGlobals = jQuery.event && s.global;
// Watch for a new set of requests
if ( fireGlobals && jQuery.active++ === 0 ) {
jQuery.event.trigger( "ajaxStart" );
s.type = s.type.toUpperCase();
// Determine if request has content
s.hasContent = !rnoContent.test( s.type );
// Save the URL in case we're toying with the If-Modified-Since
// and/or If-None-Match header later on
// Remove hash to simplify url manipulation
cacheURL = s.url.replace( rhash, "" );
// More options handling for requests with no content
// Remember the hash so we can put it back
uncached = s.url.slice( cacheURL.length );
// If data is available and should be processed, append data to url
if ( s.data && ( s.processData || typeof s.data === "string" ) ) {
cacheURL += ( rquery.test( cacheURL ) ? "&" : "?" ) + s.data;
// #9682: remove data so that it's not used in an eventual retry
// Add or update anti-cache param if needed
if ( s.cache === false ) {
cacheURL = cacheURL.replace( rantiCache, "$1" );
uncached = ( rquery.test( cacheURL ) ? "&" : "?" ) + "_=" + ( nonce.guid++ ) +
// Put hash and anti-cache on the URL that will be requested (gh-1732)
s.url = cacheURL + uncached;
// Change '%20' to '+' if this is encoded form body content (gh-2658)
} else if ( s.data && s.processData &&
( s.contentType || "" ).indexOf( "application/x-www-form-urlencoded" ) === 0 ) {
s.data = s.data.replace( r20, "+" );
// Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
if ( jQuery.lastModified[ cacheURL ] ) {
jqXHR.setRequestHeader( "If-Modified-Since", jQuery.lastModified[ cacheURL ] );
if ( jQuery.etag[ cacheURL ] ) {
jqXHR.setRequestHeader( "If-None-Match", jQuery.etag[ cacheURL ] );
// Set the correct header, if data is being sent
if ( s.data && s.hasContent && s.contentType !== false || options.contentType ) {
jqXHR.setRequestHeader( "Content-Type", s.contentType );
// Set the Accepts header for the server, depending on the dataType
s.dataTypes[ 0 ] && s.accepts[ s.dataTypes[ 0 ] ] ?
s.accepts[ s.dataTypes[ 0 ] ] +
( s.dataTypes[ 0 ] !== "*" ? ", " + allTypes + "; q=0.01" : "" ) :
// Check for headers option
jqXHR.setRequestHeader( i, s.headers[ i ] );
// Allow custom headers/mimetypes and early abort
( s.beforeSend.call( callbackContext, jqXHR, s ) === false || completed ) ) {
// Abort if not done already and return
// Aborting is no longer a cancellation
// Install callbacks on deferreds
completeDeferred.add( s.complete );
transport = inspectPrefiltersOrTransports( transports, s, options, jqXHR );
// If no transport, we auto-abort
done( -1, "No Transport" );
globalEventContext.trigger( "ajaxSend", [ jqXHR, s ] );
// If request was aborted inside ajaxSend, stop there
if ( s.async && s.timeout > 0 ) {
timeoutTimer = window.setTimeout( function() {
jqXHR.abort( "timeout" );
transport.send( requestHeaders, done );
// Rethrow post-completion exceptions
// Propagate others as results
// Callback for when everything is done
function done( status, nativeStatusText, responses, headers ) {
var isSuccess, success, error, response, modified,
statusText = nativeStatusText;
// Ignore repeat invocations
// Clear timeout if it exists
window.clearTimeout( timeoutTimer );
// Dereference transport for early garbage collection
// (no matter how long the jqXHR object will be used)
// Cache response headers
responseHeadersString = headers || "";
jqXHR.readyState = status > 0 ? 4 : 0;
// Determine if successful
isSuccess = status >= 200 && status < 300 || status === 304;
response = ajaxHandleResponses( s, jqXHR, responses );
// Use a noop converter for missing script
if ( !isSuccess && jQuery.inArray( "script", s.dataTypes ) > -1 ) {
s.converters[ "text script" ] = function() {};
// Convert no matter what (that way responseXXX fields are always set)
response = ajaxConvert( s, response, jqXHR, isSuccess );
// If successful, handle type chaining
// Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
modified = jqXHR.getResponseHeader( "Last-Modified" );
jQuery.lastModified[ cacheURL ] = modified;
modified = jqXHR.getResponseHeader( "etag" );
jQuery.etag[ cacheURL ] = modified;
if ( status === 204 || s.type === "HEAD" ) {
statusText = "nocontent";
} else if ( status === 304 ) {
statusText = "notmodified";
// If we have data, let's convert it
statusText = response.state;
// Extract error from statusText and normalize for non-aborts
if ( status || !statusText ) {
// Set data for the fake xhr object
jqXHR.statusText = ( nativeStatusText || statusText ) + "";
deferred.resolveWith( callbackContext, [ success, statusText, jqXHR ] );
deferred.rejectWith( callbackContext, [ jqXHR, statusText, error ] );
// Status-dependent callbacks
jqXHR.statusCode( statusCode );
globalEventContext.trigger( isSuccess ? "ajaxSuccess" : "ajaxError",
[ jqXHR, s, isSuccess ? success : error ] );
completeDeferred.fireWith( callbackContext, [ jqXHR, statusText ] );
globalEventContext.trigger( "ajaxComplete", [ jqXHR, s ] );
// Handle the global AJAX counter
if ( !( --jQuery.active ) ) {
jQuery.event.trigger( "ajaxStop" );
getJSON: function( url, data, callback ) {
return jQuery.get( url, data, callback, "json" );
getScript: function( url, callback ) {
return jQuery.get( url, undefined, callback, "script" );
jQuery.each( [ "get", "post" ], function( _i, method ) {
jQuery[ method ] = function( url, data, callback, type ) {
// Shift arguments if data argument was omitted
if ( isFunction( data ) ) {
// The url can be an options object (which then must have .url)
return jQuery.ajax( jQuery.extend( {
}, jQuery.isPlainObject( url ) && url ) );
jQuery.ajaxPrefilter( function( s ) {
if ( i.toLowerCase() === "content-type" ) {
s.contentType = s.headers[ i ] || "";
jQuery._evalUrl = function( url, options, doc ) {
// Make this explicit, since user can override this through ajaxSetup (#11264)
// Only evaluate the response if it is successful (gh-4126)
// dataFilter is not invoked for failure responses, so using it instead
// of the default converter is kludgy but it works.
"text script": function() {}
dataFilter: function( response ) {
jQuery.globalEval( response, options, doc );
wrapAll: function( html ) {
if ( isFunction( html ) ) {
html = html.call( this[ 0 ] );
// The elements to wrap the target around
wrap = jQuery( html, this[ 0 ].ownerDocument ).eq( 0 ).clone( true );
if ( this[ 0 ].parentNode ) {
wrap.insertBefore( this[ 0 ] );
while ( elem.firstElementChild ) {
elem = elem.firstElementChild;
wrapInner: function( html ) {
if ( isFunction( html ) ) {
return this.each( function( i ) {
jQuery( this ).wrapInner( html.call( this, i ) );
return this.each( function() {
var self = jQuery( this ),
contents = self.contents();
contents.wrapAll( html );
var htmlIsFunction = isFunction( html );
return this.each( function( i ) {
jQuery( this ).wrapAll( htmlIsFunction ? html.call( this, i ) : html );
unwrap: function( selector ) {
this.parent( selector ).not( "body" ).each( function() {
jQuery( this ).replaceWith( this.childNodes );
jQuery.expr.pseudos.hidden = function( elem ) {
return !jQuery.expr.pseudos.visible( elem );
jQuery.expr.pseudos.visible = function( elem ) {
return !!( elem.offsetWidth || elem.offsetHeight || elem.getClientRects().length );
jQuery.ajaxSettings.xhr = function() {
return new window.XMLHttpRequest();
// File protocol always yields status code 0, assume 200
// #1450: sometimes IE returns 1223 when it should be 204
xhrSupported = jQuery.ajaxSettings.xhr();
support.cors = !!xhrSupported && ( "withCredentials" in xhrSupported );
support.ajax = xhrSupported = !!xhrSupported;
jQuery.ajaxTransport( function( options ) {
var callback, errorCallback;
// Cross domain only allowed if supported through XMLHttpRequest
if ( support.cors || xhrSupported && !options.crossDomain ) {
send: function( headers, complete ) {
// Apply custom fields if provided
if ( options.xhrFields ) {
for ( i in options.xhrFields ) {
xhr[ i ] = options.xhrFields[ i ];