| 1 | define( [
|
| 2 | "./core",
|
| 3 | "./var/document",
|
| 4 | "./var/isFunction",
|
| 5 | "./var/rnothtmlwhite",
|
| 6 | "./ajax/var/location",
|
| 7 | "./ajax/var/nonce",
|
| 8 | "./ajax/var/rquery",
|
| 9 |
|
| 10 | "./core/init",
|
| 11 | "./core/parseXML",
|
| 12 | "./event/trigger",
|
| 13 | "./deferred",
|
| 14 | "./serialize"
|
| 15 | ], function( jQuery, document, isFunction, rnothtmlwhite, location, nonce, rquery ) {
|
| 16 |
|
| 17 | "use strict";
|
| 18 |
|
| 19 | var
|
| 20 | r20 = /%20/g,
|
| 21 | rhash = /#.*$/,
|
| 22 | rantiCache = /([?&])_=[^&]*/,
|
| 23 | rheaders = /^(.*?):[ \t]*([^\r\n]*)$/mg,
|
| 24 |
|
| 25 |
|
| 26 | rlocalProtocol = /^(?:about|app|app-storage|.+-extension|file|res|widget):$/,
|
| 27 | rnoContent = /^(?:GET|HEAD)$/,
|
| 28 | rprotocol = /^\/\//,
|
| 29 |
|
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 |
|
| 39 | prefilters = {},
|
| 40 |
|
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 |
|
| 46 | transports = {},
|
| 47 |
|
| 48 |
|
| 49 | allTypes = "*/".concat( "*" ),
|
| 50 |
|
| 51 |
|
| 52 | originAnchor = document.createElement( "a" );
|
| 53 | originAnchor.href = location.href;
|
| 54 |
|
| 55 |
|
| 56 | function addToPrefiltersOrTransports( structure ) {
|
| 57 |
|
| 58 |
|
| 59 | return function( dataTypeExpression, func ) {
|
| 60 |
|
| 61 | if ( typeof dataTypeExpression !== "string" ) {
|
| 62 | func = dataTypeExpression;
|
| 63 | dataTypeExpression = "*";
|
| 64 | }
|
| 65 |
|
| 66 | var dataType,
|
| 67 | i = 0,
|
| 68 | dataTypes = dataTypeExpression.toLowerCase().match( rnothtmlwhite ) || [];
|
| 69 |
|
| 70 | if ( isFunction( func ) ) {
|
| 71 |
|
| 72 |
|
| 73 | while ( ( dataType = dataTypes[ i++ ] ) ) {
|
| 74 |
|
| 75 |
|
| 76 | if ( dataType[ 0 ] === "+" ) {
|
| 77 | dataType = dataType.slice( 1 ) || "*";
|
| 78 | ( structure[ dataType ] = structure[ dataType ] || [] ).unshift( func );
|
| 79 |
|
| 80 |
|
| 81 | } else {
|
| 82 | ( structure[ dataType ] = structure[ dataType ] || [] ).push( func );
|
| 83 | }
|
| 84 | }
|
| 85 | }
|
| 86 | };
|
| 87 | }
|
| 88 |
|
| 89 |
|
| 90 | function inspectPrefiltersOrTransports( structure, options, originalOptions, jqXHR ) {
|
| 91 |
|
| 92 | var inspected = {},
|
| 93 | seekingTransport = ( structure === transports );
|
| 94 |
|
| 95 | function inspect( dataType ) {
|
| 96 | var selected;
|
| 97 | inspected[ dataType ] = true;
|
| 98 | jQuery.each( structure[ dataType ] || [], function( _, prefilterOrFactory ) {
|
| 99 | var dataTypeOrTransport = prefilterOrFactory( options, originalOptions, jqXHR );
|
| 100 | if ( typeof dataTypeOrTransport === "string" &&
|
| 101 | !seekingTransport && !inspected[ dataTypeOrTransport ] ) {
|
| 102 |
|
| 103 | options.dataTypes.unshift( dataTypeOrTransport );
|
| 104 | inspect( dataTypeOrTransport );
|
| 105 | return false;
|
| 106 | } else if ( seekingTransport ) {
|
| 107 | return !( selected = dataTypeOrTransport );
|
| 108 | }
|
| 109 | } );
|
| 110 | return selected;
|
| 111 | }
|
| 112 |
|
| 113 | return inspect( options.dataTypes[ 0 ] ) || !inspected[ "*" ] && inspect( "*" );
|
| 114 | }
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 | function ajaxExtend( target, src ) {
|
| 120 | var key, deep,
|
| 121 | flatOptions = jQuery.ajaxSettings.flatOptions || {};
|
| 122 |
|
| 123 | for ( key in src ) {
|
| 124 | if ( src[ key ] !== undefined ) {
|
| 125 | ( flatOptions[ key ] ? target : ( deep || ( deep = {} ) ) )[ key ] = src[ key ];
|
| 126 | }
|
| 127 | }
|
| 128 | if ( deep ) {
|
| 129 | jQuery.extend( true, target, deep );
|
| 130 | }
|
| 131 |
|
| 132 | return target;
|
| 133 | }
|
| 134 |
|
| 135 | |
| 136 | |
| 137 | |
| 138 |
|
| 139 | function ajaxHandleResponses( s, jqXHR, responses ) {
|
| 140 |
|
| 141 | var ct, type, finalDataType, firstDataType,
|
| 142 | contents = s.contents,
|
| 143 | dataTypes = s.dataTypes;
|
| 144 |
|
| 145 |
|
| 146 | while ( dataTypes[ 0 ] === "*" ) {
|
| 147 | dataTypes.shift();
|
| 148 | if ( ct === undefined ) {
|
| 149 | ct = s.mimeType || jqXHR.getResponseHeader( "Content-Type" );
|
| 150 | }
|
| 151 | }
|
| 152 |
|
| 153 |
|
| 154 | if ( ct ) {
|
| 155 | for ( type in contents ) {
|
| 156 | if ( contents[ type ] && contents[ type ].test( ct ) ) {
|
| 157 | dataTypes.unshift( type );
|
| 158 | break;
|
| 159 | }
|
| 160 | }
|
| 161 | }
|
| 162 |
|
| 163 |
|
| 164 | if ( dataTypes[ 0 ] in responses ) {
|
| 165 | finalDataType = dataTypes[ 0 ];
|
| 166 | } else {
|
| 167 |
|
| 168 |
|
| 169 | for ( type in responses ) {
|
| 170 | if ( !dataTypes[ 0 ] || s.converters[ type + " " + dataTypes[ 0 ] ] ) {
|
| 171 | finalDataType = type;
|
| 172 | break;
|
| 173 | }
|
| 174 | if ( !firstDataType ) {
|
| 175 | firstDataType = type;
|
| 176 | }
|
| 177 | }
|
| 178 |
|
| 179 |
|
| 180 | finalDataType = finalDataType || firstDataType;
|
| 181 | }
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 | if ( finalDataType ) {
|
| 187 | if ( finalDataType !== dataTypes[ 0 ] ) {
|
| 188 | dataTypes.unshift( finalDataType );
|
| 189 | }
|
| 190 | return responses[ finalDataType ];
|
| 191 | }
|
| 192 | }
|
| 193 |
|
| 194 | |
| 195 | |
| 196 |
|
| 197 | function ajaxConvert( s, response, jqXHR, isSuccess ) {
|
| 198 | var conv2, current, conv, tmp, prev,
|
| 199 | converters = {},
|
| 200 |
|
| 201 |
|
| 202 | dataTypes = s.dataTypes.slice();
|
| 203 |
|
| 204 |
|
| 205 | if ( dataTypes[ 1 ] ) {
|
| 206 | for ( conv in s.converters ) {
|
| 207 | converters[ conv.toLowerCase() ] = s.converters[ conv ];
|
| 208 | }
|
| 209 | }
|
| 210 |
|
| 211 | current = dataTypes.shift();
|
| 212 |
|
| 213 |
|
| 214 | while ( current ) {
|
| 215 |
|
| 216 | if ( s.responseFields[ current ] ) {
|
| 217 | jqXHR[ s.responseFields[ current ] ] = response;
|
| 218 | }
|
| 219 |
|
| 220 |
|
| 221 | if ( !prev && isSuccess && s.dataFilter ) {
|
| 222 | response = s.dataFilter( response, s.dataType );
|
| 223 | }
|
| 224 |
|
| 225 | prev = current;
|
| 226 | current = dataTypes.shift();
|
| 227 |
|
| 228 | if ( current ) {
|
| 229 |
|
| 230 |
|
| 231 | if ( current === "*" ) {
|
| 232 |
|
| 233 | current = prev;
|
| 234 |
|
| 235 |
|
| 236 | } else if ( prev !== "*" && prev !== current ) {
|
| 237 |
|
| 238 |
|
| 239 | conv = converters[ prev + " " + current ] || converters[ "* " + current ];
|
| 240 |
|
| 241 |
|
| 242 | if ( !conv ) {
|
| 243 | for ( conv2 in converters ) {
|
| 244 |
|
| 245 |
|
| 246 | tmp = conv2.split( " " );
|
| 247 | if ( tmp[ 1 ] === current ) {
|
| 248 |
|
| 249 |
|
| 250 | conv = converters[ prev + " " + tmp[ 0 ] ] ||
|
| 251 | converters[ "* " + tmp[ 0 ] ];
|
| 252 | if ( conv ) {
|
| 253 |
|
| 254 |
|
| 255 | if ( conv === true ) {
|
| 256 | conv = converters[ conv2 ];
|
| 257 |
|
| 258 |
|
| 259 | } else if ( converters[ conv2 ] !== true ) {
|
| 260 | current = tmp[ 0 ];
|
| 261 | dataTypes.unshift( tmp[ 1 ] );
|
| 262 | }
|
| 263 | break;
|
| 264 | }
|
| 265 | }
|
| 266 | }
|
| 267 | }
|
| 268 |
|
| 269 |
|
| 270 | if ( conv !== true ) {
|
| 271 |
|
| 272 |
|
| 273 | if ( conv && s.throws ) {
|
| 274 | response = conv( response );
|
| 275 | } else {
|
| 276 | try {
|
| 277 | response = conv( response );
|
| 278 | } catch ( e ) {
|
| 279 | return {
|
| 280 | state: "parsererror",
|
| 281 | error: conv ? e : "No conversion from " + prev + " to " + current
|
| 282 | };
|
| 283 | }
|
| 284 | }
|
| 285 | }
|
| 286 | }
|
| 287 | }
|
| 288 | }
|
| 289 |
|
| 290 | return { state: "success", data: response };
|
| 291 | }
|
| 292 |
|
| 293 | jQuery.extend( {
|
| 294 |
|
| 295 |
|
| 296 | active: 0,
|
| 297 |
|
| 298 |
|
| 299 | lastModified: {},
|
| 300 | etag: {},
|
| 301 |
|
| 302 | ajaxSettings: {
|
| 303 | url: location.href,
|
| 304 | type: "GET",
|
| 305 | isLocal: rlocalProtocol.test( location.protocol ),
|
| 306 | global: true,
|
| 307 | processData: true,
|
| 308 | async: true,
|
| 309 | contentType: "application/x-www-form-urlencoded; charset=UTF-8",
|
| 310 |
|
| 311 | |
| 312 | |
| 313 | |
| 314 | |
| 315 | |
| 316 | |
| 317 | |
| 318 | |
| 319 | |
| 320 | |
| 321 |
|
| 322 |
|
| 323 | accepts: {
|
| 324 | "*": allTypes,
|
| 325 | text: "text/plain",
|
| 326 | html: "text/html",
|
| 327 | xml: "application/xml, text/xml",
|
| 328 | json: "application/json, text/javascript"
|
| 329 | },
|
| 330 |
|
| 331 | contents: {
|
| 332 | xml: /\bxml\b/,
|
| 333 | html: /\bhtml/,
|
| 334 | json: /\bjson\b/
|
| 335 | },
|
| 336 |
|
| 337 | responseFields: {
|
| 338 | xml: "responseXML",
|
| 339 | text: "responseText",
|
| 340 | json: "responseJSON"
|
| 341 | },
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 | converters: {
|
| 346 |
|
| 347 |
|
| 348 | "* text": String,
|
| 349 |
|
| 350 |
|
| 351 | "text html": true,
|
| 352 |
|
| 353 |
|
| 354 | "text json": JSON.parse,
|
| 355 |
|
| 356 |
|
| 357 | "text xml": jQuery.parseXML
|
| 358 | },
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 | flatOptions: {
|
| 365 | url: true,
|
| 366 | context: true
|
| 367 | }
|
| 368 | },
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 | ajaxSetup: function( target, settings ) {
|
| 374 | return settings ?
|
| 375 |
|
| 376 |
|
| 377 | ajaxExtend( ajaxExtend( target, jQuery.ajaxSettings ), settings ) :
|
| 378 |
|
| 379 |
|
| 380 | ajaxExtend( jQuery.ajaxSettings, target );
|
| 381 | },
|
| 382 |
|
| 383 | ajaxPrefilter: addToPrefiltersOrTransports( prefilters ),
|
| 384 | ajaxTransport: addToPrefiltersOrTransports( transports ),
|
| 385 |
|
| 386 |
|
| 387 | ajax: function( url, options ) {
|
| 388 |
|
| 389 |
|
| 390 | if ( typeof url === "object" ) {
|
| 391 | options = url;
|
| 392 | url = undefined;
|
| 393 | }
|
| 394 |
|
| 395 |
|
| 396 | options = options || {};
|
| 397 |
|
| 398 | var transport,
|
| 399 |
|
| 400 |
|
| 401 | cacheURL,
|
| 402 |
|
| 403 |
|
| 404 | responseHeadersString,
|
| 405 | responseHeaders,
|
| 406 |
|
| 407 |
|
| 408 | timeoutTimer,
|
| 409 |
|
| 410 |
|
| 411 | urlAnchor,
|
| 412 |
|
| 413 |
|
| 414 | completed,
|
| 415 |
|
| 416 |
|
| 417 | fireGlobals,
|
| 418 |
|
| 419 |
|
| 420 | i,
|
| 421 |
|
| 422 |
|
| 423 | uncached,
|
| 424 |
|
| 425 |
|
| 426 | s = jQuery.ajaxSetup( {}, options ),
|
| 427 |
|
| 428 |
|
| 429 | callbackContext = s.context || s,
|
| 430 |
|
| 431 |
|
| 432 | globalEventContext = s.context &&
|
| 433 | ( callbackContext.nodeType || callbackContext.jquery ) ?
|
| 434 | jQuery( callbackContext ) :
|
| 435 | jQuery.event,
|
| 436 |
|
| 437 |
|
| 438 | deferred = jQuery.Deferred(),
|
| 439 | completeDeferred = jQuery.Callbacks( "once memory" ),
|
| 440 |
|
| 441 |
|
| 442 | statusCode = s.statusCode || {},
|
| 443 |
|
| 444 |
|
| 445 | requestHeaders = {},
|
| 446 | requestHeadersNames = {},
|
| 447 |
|
| 448 |
|
| 449 | strAbort = "canceled",
|
| 450 |
|
| 451 |
|
| 452 | jqXHR = {
|
| 453 | readyState: 0,
|
| 454 |
|
| 455 |
|
| 456 | getResponseHeader: function( key ) {
|
| 457 | var match;
|
| 458 | if ( completed ) {
|
| 459 | if ( !responseHeaders ) {
|
| 460 | responseHeaders = {};
|
| 461 | while ( ( match = rheaders.exec( responseHeadersString ) ) ) {
|
| 462 | responseHeaders[ match[ 1 ].toLowerCase() + " " ] =
|
| 463 | ( responseHeaders[ match[ 1 ].toLowerCase() + " " ] || [] )
|
| 464 | .concat( match[ 2 ] );
|
| 465 | }
|
| 466 | }
|
| 467 | match = responseHeaders[ key.toLowerCase() + " " ];
|
| 468 | }
|
| 469 | return match == null ? null : match.join( ", " );
|
| 470 | },
|
| 471 |
|
| 472 |
|
| 473 | getAllResponseHeaders: function() {
|
| 474 | return completed ? responseHeadersString : null;
|
| 475 | },
|
| 476 |
|
| 477 |
|
| 478 | setRequestHeader: function( name, value ) {
|
| 479 | if ( completed == null ) {
|
| 480 | name = requestHeadersNames[ name.toLowerCase() ] =
|
| 481 | requestHeadersNames[ name.toLowerCase() ] || name;
|
| 482 | requestHeaders[ name ] = value;
|
| 483 | }
|
| 484 | return this;
|
| 485 | },
|
| 486 |
|
| 487 |
|
| 488 | overrideMimeType: function( type ) {
|
| 489 | if ( completed == null ) {
|
| 490 | s.mimeType = type;
|
| 491 | }
|
| 492 | return this;
|
| 493 | },
|
| 494 |
|
| 495 |
|
| 496 | statusCode: function( map ) {
|
| 497 | var code;
|
| 498 | if ( map ) {
|
| 499 | if ( completed ) {
|
| 500 |
|
| 501 |
|
| 502 | jqXHR.always( map[ jqXHR.status ] );
|
| 503 | } else {
|
| 504 |
|
| 505 |
|
| 506 | for ( code in map ) {
|
| 507 | statusCode[ code ] = [ statusCode[ code ], map[ code ] ];
|
| 508 | }
|
| 509 | }
|
| 510 | }
|
| 511 | return this;
|
| 512 | },
|
| 513 |
|
| 514 |
|
| 515 | abort: function( statusText ) {
|
| 516 | var finalText = statusText || strAbort;
|
| 517 | if ( transport ) {
|
| 518 | transport.abort( finalText );
|
| 519 | }
|
| 520 | done( 0, finalText );
|
| 521 | return this;
|
| 522 | }
|
| 523 | };
|
| 524 |
|
| 525 |
|
| 526 | deferred.promise( jqXHR );
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 | s.url = ( ( url || s.url || location.href ) + "" )
|
| 532 | .replace( rprotocol, location.protocol + "//" );
|
| 533 |
|
| 534 |
|
| 535 | s.type = options.method || options.type || s.method || s.type;
|
| 536 |
|
| 537 |
|
| 538 | s.dataTypes = ( s.dataType || "*" ).toLowerCase().match( rnothtmlwhite ) || [ "" ];
|
| 539 |
|
| 540 |
|
| 541 | if ( s.crossDomain == null ) {
|
| 542 | urlAnchor = document.createElement( "a" );
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 | try {
|
| 548 | urlAnchor.href = s.url;
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 | urlAnchor.href = urlAnchor.href;
|
| 553 | s.crossDomain = originAnchor.protocol + "//" + originAnchor.host !==
|
| 554 | urlAnchor.protocol + "//" + urlAnchor.host;
|
| 555 | } catch ( e ) {
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 | s.crossDomain = true;
|
| 560 | }
|
| 561 | }
|
| 562 |
|
| 563 |
|
| 564 | if ( s.data && s.processData && typeof s.data !== "string" ) {
|
| 565 | s.data = jQuery.param( s.data, s.traditional );
|
| 566 | }
|
| 567 |
|
| 568 |
|
| 569 | inspectPrefiltersOrTransports( prefilters, s, options, jqXHR );
|
| 570 |
|
| 571 |
|
| 572 | if ( completed ) {
|
| 573 | return jqXHR;
|
| 574 | }
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 | fireGlobals = jQuery.event && s.global;
|
| 579 |
|
| 580 |
|
| 581 | if ( fireGlobals && jQuery.active++ === 0 ) {
|
| 582 | jQuery.event.trigger( "ajaxStart" );
|
| 583 | }
|
| 584 |
|
| 585 |
|
| 586 | s.type = s.type.toUpperCase();
|
| 587 |
|
| 588 |
|
| 589 | s.hasContent = !rnoContent.test( s.type );
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 | cacheURL = s.url.replace( rhash, "" );
|
| 595 |
|
| 596 |
|
| 597 | if ( !s.hasContent ) {
|
| 598 |
|
| 599 |
|
| 600 | uncached = s.url.slice( cacheURL.length );
|
| 601 |
|
| 602 |
|
| 603 | if ( s.data && ( s.processData || typeof s.data === "string" ) ) {
|
| 604 | cacheURL += ( rquery.test( cacheURL ) ? "&" : "?" ) + s.data;
|
| 605 |
|
| 606 |
|
| 607 | delete s.data;
|
| 608 | }
|
| 609 |
|
| 610 |
|
| 611 | if ( s.cache === false ) {
|
| 612 | cacheURL = cacheURL.replace( rantiCache, "$1" );
|
| 613 | uncached = ( rquery.test( cacheURL ) ? "&" : "?" ) + "_=" + ( nonce.guid++ ) +
|
| 614 | uncached;
|
| 615 | }
|
| 616 |
|
| 617 |
|
| 618 | s.url = cacheURL + uncached;
|
| 619 |
|
| 620 |
|
| 621 | } else if ( s.data && s.processData &&
|
| 622 | ( s.contentType || "" ).indexOf( "application/x-www-form-urlencoded" ) === 0 ) {
|
| 623 | s.data = s.data.replace( r20, "+" );
|
| 624 | }
|
| 625 |
|
| 626 |
|
| 627 | if ( s.ifModified ) {
|
| 628 | if ( jQuery.lastModified[ cacheURL ] ) {
|
| 629 | jqXHR.setRequestHeader( "If-Modified-Since", jQuery.lastModified[ cacheURL ] );
|
| 630 | }
|
| 631 | if ( jQuery.etag[ cacheURL ] ) {
|
| 632 | jqXHR.setRequestHeader( "If-None-Match", jQuery.etag[ cacheURL ] );
|
| 633 | }
|
| 634 | }
|
| 635 |
|
| 636 |
|
| 637 | if ( s.data && s.hasContent && s.contentType !== false || options.contentType ) {
|
| 638 | jqXHR.setRequestHeader( "Content-Type", s.contentType );
|
| 639 | }
|
| 640 |
|
| 641 |
|
| 642 | jqXHR.setRequestHeader(
|
| 643 | "Accept",
|
| 644 | s.dataTypes[ 0 ] && s.accepts[ s.dataTypes[ 0 ] ] ?
|
| 645 | s.accepts[ s.dataTypes[ 0 ] ] +
|
| 646 | ( s.dataTypes[ 0 ] !== "*" ? ", " + allTypes + "; q=0.01" : "" ) :
|
| 647 | s.accepts[ "*" ]
|
| 648 | );
|
| 649 |
|
| 650 |
|
| 651 | for ( i in s.headers ) {
|
| 652 | jqXHR.setRequestHeader( i, s.headers[ i ] );
|
| 653 | }
|
| 654 |
|
| 655 |
|
| 656 | if ( s.beforeSend &&
|
| 657 | ( s.beforeSend.call( callbackContext, jqXHR, s ) === false || completed ) ) {
|
| 658 |
|
| 659 |
|
| 660 | return jqXHR.abort();
|
| 661 | }
|
| 662 |
|
| 663 |
|
| 664 | strAbort = "abort";
|
| 665 |
|
| 666 |
|
| 667 | completeDeferred.add( s.complete );
|
| 668 | jqXHR.done( s.success );
|
| 669 | jqXHR.fail( s.error );
|
| 670 |
|
| 671 |
|
| 672 | transport = inspectPrefiltersOrTransports( transports, s, options, jqXHR );
|
| 673 |
|
| 674 |
|
| 675 | if ( !transport ) {
|
| 676 | done( -1, "No Transport" );
|
| 677 | } else {
|
| 678 | jqXHR.readyState = 1;
|
| 679 |
|
| 680 |
|
| 681 | if ( fireGlobals ) {
|
| 682 | globalEventContext.trigger( "ajaxSend", [ jqXHR, s ] );
|
| 683 | }
|
| 684 |
|
| 685 |
|
| 686 | if ( completed ) {
|
| 687 | return jqXHR;
|
| 688 | }
|
| 689 |
|
| 690 |
|
| 691 | if ( s.async && s.timeout > 0 ) {
|
| 692 | timeoutTimer = window.setTimeout( function() {
|
| 693 | jqXHR.abort( "timeout" );
|
| 694 | }, s.timeout );
|
| 695 | }
|
| 696 |
|
| 697 | try {
|
| 698 | completed = false;
|
| 699 | transport.send( requestHeaders, done );
|
| 700 | } catch ( e ) {
|
| 701 |
|
| 702 |
|
| 703 | if ( completed ) {
|
| 704 | throw e;
|
| 705 | }
|
| 706 |
|
| 707 |
|
| 708 | done( -1, e );
|
| 709 | }
|
| 710 | }
|
| 711 |
|
| 712 |
|
| 713 | function done( status, nativeStatusText, responses, headers ) {
|
| 714 | var isSuccess, success, error, response, modified,
|
| 715 | statusText = nativeStatusText;
|
| 716 |
|
| 717 |
|
| 718 | if ( completed ) {
|
| 719 | return;
|
| 720 | }
|
| 721 |
|
| 722 | completed = true;
|
| 723 |
|
| 724 |
|
| 725 | if ( timeoutTimer ) {
|
| 726 | window.clearTimeout( timeoutTimer );
|
| 727 | }
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 | transport = undefined;
|
| 732 |
|
| 733 |
|
| 734 | responseHeadersString = headers || "";
|
| 735 |
|
| 736 |
|
| 737 | jqXHR.readyState = status > 0 ? 4 : 0;
|
| 738 |
|
| 739 |
|
| 740 | isSuccess = status >= 200 && status < 300 || status === 304;
|
| 741 |
|
| 742 |
|
| 743 | if ( responses ) {
|
| 744 | response = ajaxHandleResponses( s, jqXHR, responses );
|
| 745 | }
|
| 746 |
|
| 747 |
|
| 748 | if ( !isSuccess && jQuery.inArray( "script", s.dataTypes ) > -1 ) {
|
| 749 | s.converters[ "text script" ] = function() {};
|
| 750 | }
|
| 751 |
|
| 752 |
|
| 753 | response = ajaxConvert( s, response, jqXHR, isSuccess );
|
| 754 |
|
| 755 |
|
| 756 | if ( isSuccess ) {
|
| 757 |
|
| 758 |
|
| 759 | if ( s.ifModified ) {
|
| 760 | modified = jqXHR.getResponseHeader( "Last-Modified" );
|
| 761 | if ( modified ) {
|
| 762 | jQuery.lastModified[ cacheURL ] = modified;
|
| 763 | }
|
| 764 | modified = jqXHR.getResponseHeader( "etag" );
|
| 765 | if ( modified ) {
|
| 766 | jQuery.etag[ cacheURL ] = modified;
|
| 767 | }
|
| 768 | }
|
| 769 |
|
| 770 |
|
| 771 | if ( status === 204 || s.type === "HEAD" ) {
|
| 772 | statusText = "nocontent";
|
| 773 |
|
| 774 |
|
| 775 | } else if ( status === 304 ) {
|
| 776 | statusText = "notmodified";
|
| 777 |
|
| 778 |
|
| 779 | } else {
|
| 780 | statusText = response.state;
|
| 781 | success = response.data;
|
| 782 | error = response.error;
|
| 783 | isSuccess = !error;
|
| 784 | }
|
| 785 | } else {
|
| 786 |
|
| 787 |
|
| 788 | error = statusText;
|
| 789 | if ( status || !statusText ) {
|
| 790 | statusText = "error";
|
| 791 | if ( status < 0 ) {
|
| 792 | status = 0;
|
| 793 | }
|
| 794 | }
|
| 795 | }
|
| 796 |
|
| 797 |
|
| 798 | jqXHR.status = status;
|
| 799 | jqXHR.statusText = ( nativeStatusText || statusText ) + "";
|
| 800 |
|
| 801 |
|
| 802 | if ( isSuccess ) {
|
| 803 | deferred.resolveWith( callbackContext, [ success, statusText, jqXHR ] );
|
| 804 | } else {
|
| 805 | deferred.rejectWith( callbackContext, [ jqXHR, statusText, error ] );
|
| 806 | }
|
| 807 |
|
| 808 |
|
| 809 | jqXHR.statusCode( statusCode );
|
| 810 | statusCode = undefined;
|
| 811 |
|
| 812 | if ( fireGlobals ) {
|
| 813 | globalEventContext.trigger( isSuccess ? "ajaxSuccess" : "ajaxError",
|
| 814 | [ jqXHR, s, isSuccess ? success : error ] );
|
| 815 | }
|
| 816 |
|
| 817 |
|
| 818 | completeDeferred.fireWith( callbackContext, [ jqXHR, statusText ] );
|
| 819 |
|
| 820 | if ( fireGlobals ) {
|
| 821 | globalEventContext.trigger( "ajaxComplete", [ jqXHR, s ] );
|
| 822 |
|
| 823 |
|
| 824 | if ( !( --jQuery.active ) ) {
|
| 825 | jQuery.event.trigger( "ajaxStop" );
|
| 826 | }
|
| 827 | }
|
| 828 | }
|
| 829 |
|
| 830 | return jqXHR;
|
| 831 | },
|
| 832 |
|
| 833 | getJSON: function( url, data, callback ) {
|
| 834 | return jQuery.get( url, data, callback, "json" );
|
| 835 | },
|
| 836 |
|
| 837 | getScript: function( url, callback ) {
|
| 838 | return jQuery.get( url, undefined, callback, "script" );
|
| 839 | }
|
| 840 | } );
|
| 841 |
|
| 842 | jQuery.each( [ "get", "post" ], function( _i, method ) {
|
| 843 | jQuery[ method ] = function( url, data, callback, type ) {
|
| 844 |
|
| 845 |
|
| 846 | if ( isFunction( data ) ) {
|
| 847 | type = type || callback;
|
| 848 | callback = data;
|
| 849 | data = undefined;
|
| 850 | }
|
| 851 |
|
| 852 |
|
| 853 | return jQuery.ajax( jQuery.extend( {
|
| 854 | url: url,
|
| 855 | type: method,
|
| 856 | dataType: type,
|
| 857 | data: data,
|
| 858 | success: callback
|
| 859 | }, jQuery.isPlainObject( url ) && url ) );
|
| 860 | };
|
| 861 | } );
|
| 862 |
|
| 863 | jQuery.ajaxPrefilter( function( s ) {
|
| 864 | var i;
|
| 865 | for ( i in s.headers ) {
|
| 866 | if ( i.toLowerCase() === "content-type" ) {
|
| 867 | s.contentType = s.headers[ i ] || "";
|
| 868 | }
|
| 869 | }
|
| 870 | } );
|
| 871 |
|
| 872 | return jQuery;
|
| 873 | } );
|