nexus site path corrected
[portal.git] / ecomp-portal-FE / client / bower_components / jquery / src / ajax.js
1 define( [
2         "./core",
3         "./var/document",
4         "./var/rnotwhite",
5         "./ajax/var/location",
6         "./ajax/var/nonce",
7         "./ajax/var/rquery",
8
9         "./core/init",
10         "./ajax/parseJSON",
11         "./ajax/parseXML",
12         "./event/trigger",
13         "./deferred"
14 ], function( jQuery, document, rnotwhite, location, nonce, rquery ) {
15
16 var
17         rhash = /#.*$/,
18         rts = /([?&])_=[^&]*/,
19         rheaders = /^(.*?):[ \t]*([^\r\n]*)$/mg,
20
21         // #7653, #8125, #8152: local protocol detection
22         rlocalProtocol = /^(?:about|app|app-storage|.+-extension|file|res|widget):$/,
23         rnoContent = /^(?:GET|HEAD)$/,
24         rprotocol = /^\/\//,
25
26         /* Prefilters
27          * 1) They are useful to introduce custom dataTypes (see ajax/jsonp.js for an example)
28          * 2) These are called:
29          *    - BEFORE asking for a transport
30          *    - AFTER param serialization (s.data is a string if s.processData is true)
31          * 3) key is the dataType
32          * 4) the catchall symbol "*" can be used
33          * 5) execution will start with transport dataType and THEN continue down to "*" if needed
34          */
35         prefilters = {},
36
37         /* Transports bindings
38          * 1) key is the dataType
39          * 2) the catchall symbol "*" can be used
40          * 3) selection will start with transport dataType and THEN go to "*" if needed
41          */
42         transports = {},
43
44         // Avoid comment-prolog char sequence (#10098); must appease lint and evade compression
45         allTypes = "*/".concat( "*" ),
46
47         // Anchor tag for parsing the document origin
48         originAnchor = document.createElement( "a" );
49         originAnchor.href = location.href;
50
51 // Base "constructor" for jQuery.ajaxPrefilter and jQuery.ajaxTransport
52 function addToPrefiltersOrTransports( structure ) {
53
54         // dataTypeExpression is optional and defaults to "*"
55         return function( dataTypeExpression, func ) {
56
57                 if ( typeof dataTypeExpression !== "string" ) {
58                         func = dataTypeExpression;
59                         dataTypeExpression = "*";
60                 }
61
62                 var dataType,
63                         i = 0,
64                         dataTypes = dataTypeExpression.toLowerCase().match( rnotwhite ) || [];
65
66                 if ( jQuery.isFunction( func ) ) {
67
68                         // For each dataType in the dataTypeExpression
69                         while ( ( dataType = dataTypes[ i++ ] ) ) {
70
71                                 // Prepend if requested
72                                 if ( dataType[ 0 ] === "+" ) {
73                                         dataType = dataType.slice( 1 ) || "*";
74                                         ( structure[ dataType ] = structure[ dataType ] || [] ).unshift( func );
75
76                                 // Otherwise append
77                                 } else {
78                                         ( structure[ dataType ] = structure[ dataType ] || [] ).push( func );
79                                 }
80                         }
81                 }
82         };
83 }
84
85 // Base inspection function for prefilters and transports
86 function inspectPrefiltersOrTransports( structure, options, originalOptions, jqXHR ) {
87
88         var inspected = {},
89                 seekingTransport = ( structure === transports );
90
91         function inspect( dataType ) {
92                 var selected;
93                 inspected[ dataType ] = true;
94                 jQuery.each( structure[ dataType ] || [], function( _, prefilterOrFactory ) {
95                         var dataTypeOrTransport = prefilterOrFactory( options, originalOptions, jqXHR );
96                         if ( typeof dataTypeOrTransport === "string" &&
97                                 !seekingTransport && !inspected[ dataTypeOrTransport ] ) {
98
99                                 options.dataTypes.unshift( dataTypeOrTransport );
100                                 inspect( dataTypeOrTransport );
101                                 return false;
102                         } else if ( seekingTransport ) {
103                                 return !( selected = dataTypeOrTransport );
104                         }
105                 } );
106                 return selected;
107         }
108
109         return inspect( options.dataTypes[ 0 ] ) || !inspected[ "*" ] && inspect( "*" );
110 }
111
112 // A special extend for ajax options
113 // that takes "flat" options (not to be deep extended)
114 // Fixes #9887
115 function ajaxExtend( target, src ) {
116         var key, deep,
117                 flatOptions = jQuery.ajaxSettings.flatOptions || {};
118
119         for ( key in src ) {
120                 if ( src[ key ] !== undefined ) {
121                         ( flatOptions[ key ] ? target : ( deep || ( deep = {} ) ) )[ key ] = src[ key ];
122                 }
123         }
124         if ( deep ) {
125                 jQuery.extend( true, target, deep );
126         }
127
128         return target;
129 }
130
131 /* Handles responses to an ajax request:
132  * - finds the right dataType (mediates between content-type and expected dataType)
133  * - returns the corresponding response
134  */
135 function ajaxHandleResponses( s, jqXHR, responses ) {
136
137         var ct, type, finalDataType, firstDataType,
138                 contents = s.contents,
139                 dataTypes = s.dataTypes;
140
141         // Remove auto dataType and get content-type in the process
142         while ( dataTypes[ 0 ] === "*" ) {
143                 dataTypes.shift();
144                 if ( ct === undefined ) {
145                         ct = s.mimeType || jqXHR.getResponseHeader( "Content-Type" );
146                 }
147         }
148
149         // Check if we're dealing with a known content-type
150         if ( ct ) {
151                 for ( type in contents ) {
152                         if ( contents[ type ] && contents[ type ].test( ct ) ) {
153                                 dataTypes.unshift( type );
154                                 break;
155                         }
156                 }
157         }
158
159         // Check to see if we have a response for the expected dataType
160         if ( dataTypes[ 0 ] in responses ) {
161                 finalDataType = dataTypes[ 0 ];
162         } else {
163
164                 // Try convertible dataTypes
165                 for ( type in responses ) {
166                         if ( !dataTypes[ 0 ] || s.converters[ type + " " + dataTypes[ 0 ] ] ) {
167                                 finalDataType = type;
168                                 break;
169                         }
170                         if ( !firstDataType ) {
171                                 firstDataType = type;
172                         }
173                 }
174
175                 // Or just use first one
176                 finalDataType = finalDataType || firstDataType;
177         }
178
179         // If we found a dataType
180         // We add the dataType to the list if needed
181         // and return the corresponding response
182         if ( finalDataType ) {
183                 if ( finalDataType !== dataTypes[ 0 ] ) {
184                         dataTypes.unshift( finalDataType );
185                 }
186                 return responses[ finalDataType ];
187         }
188 }
189
190 /* Chain conversions given the request and the original response
191  * Also sets the responseXXX fields on the jqXHR instance
192  */
193 function ajaxConvert( s, response, jqXHR, isSuccess ) {
194         var conv2, current, conv, tmp, prev,
195                 converters = {},
196
197                 // Work with a copy of dataTypes in case we need to modify it for conversion
198                 dataTypes = s.dataTypes.slice();
199
200         // Create converters map with lowercased keys
201         if ( dataTypes[ 1 ] ) {
202                 for ( conv in s.converters ) {
203                         converters[ conv.toLowerCase() ] = s.converters[ conv ];
204                 }
205         }
206
207         current = dataTypes.shift();
208
209         // Convert to each sequential dataType
210         while ( current ) {
211
212                 if ( s.responseFields[ current ] ) {
213                         jqXHR[ s.responseFields[ current ] ] = response;
214                 }
215
216                 // Apply the dataFilter if provided
217                 if ( !prev && isSuccess && s.dataFilter ) {
218                         response = s.dataFilter( response, s.dataType );
219                 }
220
221                 prev = current;
222                 current = dataTypes.shift();
223
224                 if ( current ) {
225
226                 // There's only work to do if current dataType is non-auto
227                         if ( current === "*" ) {
228
229                                 current = prev;
230
231                         // Convert response if prev dataType is non-auto and differs from current
232                         } else if ( prev !== "*" && prev !== current ) {
233
234                                 // Seek a direct converter
235                                 conv = converters[ prev + " " + current ] || converters[ "* " + current ];
236
237                                 // If none found, seek a pair
238                                 if ( !conv ) {
239                                         for ( conv2 in converters ) {
240
241                                                 // If conv2 outputs current
242                                                 tmp = conv2.split( " " );
243                                                 if ( tmp[ 1 ] === current ) {
244
245                                                         // If prev can be converted to accepted input
246                                                         conv = converters[ prev + " " + tmp[ 0 ] ] ||
247                                                                 converters[ "* " + tmp[ 0 ] ];
248                                                         if ( conv ) {
249
250                                                                 // Condense equivalence converters
251                                                                 if ( conv === true ) {
252                                                                         conv = converters[ conv2 ];
253
254                                                                 // Otherwise, insert the intermediate dataType
255                                                                 } else if ( converters[ conv2 ] !== true ) {
256                                                                         current = tmp[ 0 ];
257                                                                         dataTypes.unshift( tmp[ 1 ] );
258                                                                 }
259                                                                 break;
260                                                         }
261                                                 }
262                                         }
263                                 }
264
265                                 // Apply converter (if not an equivalence)
266                                 if ( conv !== true ) {
267
268                                         // Unless errors are allowed to bubble, catch and return them
269                                         if ( conv && s.throws ) {
270                                                 response = conv( response );
271                                         } else {
272                                                 try {
273                                                         response = conv( response );
274                                                 } catch ( e ) {
275                                                         return {
276                                                                 state: "parsererror",
277                                                                 error: conv ? e : "No conversion from " + prev + " to " + current
278                                                         };
279                                                 }
280                                         }
281                                 }
282                         }
283                 }
284         }
285
286         return { state: "success", data: response };
287 }
288
289 jQuery.extend( {
290
291         // Counter for holding the number of active queries
292         active: 0,
293
294         // Last-Modified header cache for next request
295         lastModified: {},
296         etag: {},
297
298         ajaxSettings: {
299                 url: location.href,
300                 type: "GET",
301                 isLocal: rlocalProtocol.test( location.protocol ),
302                 global: true,
303                 processData: true,
304                 async: true,
305                 contentType: "application/x-www-form-urlencoded; charset=UTF-8",
306                 /*
307                 timeout: 0,
308                 data: null,
309                 dataType: null,
310                 username: null,
311                 password: null,
312                 cache: null,
313                 throws: false,
314                 traditional: false,
315                 headers: {},
316                 */
317
318                 accepts: {
319                         "*": allTypes,
320                         text: "text/plain",
321                         html: "text/html",
322                         xml: "application/xml, text/xml",
323                         json: "application/json, text/javascript"
324                 },
325
326                 contents: {
327                         xml: /\bxml\b/,
328                         html: /\bhtml/,
329                         json: /\bjson\b/
330                 },
331
332                 responseFields: {
333                         xml: "responseXML",
334                         text: "responseText",
335                         json: "responseJSON"
336                 },
337
338                 // Data converters
339                 // Keys separate source (or catchall "*") and destination types with a single space
340                 converters: {
341
342                         // Convert anything to text
343                         "* text": String,
344
345                         // Text to html (true = no transformation)
346                         "text html": true,
347
348                         // Evaluate text as a json expression
349                         "text json": jQuery.parseJSON,
350
351                         // Parse text as xml
352                         "text xml": jQuery.parseXML
353                 },
354
355                 // For options that shouldn't be deep extended:
356                 // you can add your own custom options here if
357                 // and when you create one that shouldn't be
358                 // deep extended (see ajaxExtend)
359                 flatOptions: {
360                         url: true,
361                         context: true
362                 }
363         },
364
365         // Creates a full fledged settings object into target
366         // with both ajaxSettings and settings fields.
367         // If target is omitted, writes into ajaxSettings.
368         ajaxSetup: function( target, settings ) {
369                 return settings ?
370
371                         // Building a settings object
372                         ajaxExtend( ajaxExtend( target, jQuery.ajaxSettings ), settings ) :
373
374                         // Extending ajaxSettings
375                         ajaxExtend( jQuery.ajaxSettings, target );
376         },
377
378         ajaxPrefilter: addToPrefiltersOrTransports( prefilters ),
379         ajaxTransport: addToPrefiltersOrTransports( transports ),
380
381         // Main method
382         ajax: function( url, options ) {
383
384                 // If url is an object, simulate pre-1.5 signature
385                 if ( typeof url === "object" ) {
386                         options = url;
387                         url = undefined;
388                 }
389
390                 // Force options to be an object
391                 options = options || {};
392
393                 var transport,
394
395                         // URL without anti-cache param
396                         cacheURL,
397
398                         // Response headers
399                         responseHeadersString,
400                         responseHeaders,
401
402                         // timeout handle
403                         timeoutTimer,
404
405                         // Url cleanup var
406                         urlAnchor,
407
408                         // To know if global events are to be dispatched
409                         fireGlobals,
410
411                         // Loop variable
412                         i,
413
414                         // Create the final options object
415                         s = jQuery.ajaxSetup( {}, options ),
416
417                         // Callbacks context
418                         callbackContext = s.context || s,
419
420                         // Context for global events is callbackContext if it is a DOM node or jQuery collection
421                         globalEventContext = s.context &&
422                                 ( callbackContext.nodeType || callbackContext.jquery ) ?
423                                         jQuery( callbackContext ) :
424                                         jQuery.event,
425
426                         // Deferreds
427                         deferred = jQuery.Deferred(),
428                         completeDeferred = jQuery.Callbacks( "once memory" ),
429
430                         // Status-dependent callbacks
431                         statusCode = s.statusCode || {},
432
433                         // Headers (they are sent all at once)
434                         requestHeaders = {},
435                         requestHeadersNames = {},
436
437                         // The jqXHR state
438                         state = 0,
439
440                         // Default abort message
441                         strAbort = "canceled",
442
443                         // Fake xhr
444                         jqXHR = {
445                                 readyState: 0,
446
447                                 // Builds headers hashtable if needed
448                                 getResponseHeader: function( key ) {
449                                         var match;
450                                         if ( state === 2 ) {
451                                                 if ( !responseHeaders ) {
452                                                         responseHeaders = {};
453                                                         while ( ( match = rheaders.exec( responseHeadersString ) ) ) {
454                                                                 responseHeaders[ match[ 1 ].toLowerCase() ] = match[ 2 ];
455                                                         }
456                                                 }
457                                                 match = responseHeaders[ key.toLowerCase() ];
458                                         }
459                                         return match == null ? null : match;
460                                 },
461
462                                 // Raw string
463                                 getAllResponseHeaders: function() {
464                                         return state === 2 ? responseHeadersString : null;
465                                 },
466
467                                 // Caches the header
468                                 setRequestHeader: function( name, value ) {
469                                         var lname = name.toLowerCase();
470                                         if ( !state ) {
471                                                 name = requestHeadersNames[ lname ] = requestHeadersNames[ lname ] || name;
472                                                 requestHeaders[ name ] = value;
473                                         }
474                                         return this;
475                                 },
476
477                                 // Overrides response content-type header
478                                 overrideMimeType: function( type ) {
479                                         if ( !state ) {
480                                                 s.mimeType = type;
481                                         }
482                                         return this;
483                                 },
484
485                                 // Status-dependent callbacks
486                                 statusCode: function( map ) {
487                                         var code;
488                                         if ( map ) {
489                                                 if ( state < 2 ) {
490                                                         for ( code in map ) {
491
492                                                                 // Lazy-add the new callback in a way that preserves old ones
493                                                                 statusCode[ code ] = [ statusCode[ code ], map[ code ] ];
494                                                         }
495                                                 } else {
496
497                                                         // Execute the appropriate callbacks
498                                                         jqXHR.always( map[ jqXHR.status ] );
499                                                 }
500                                         }
501                                         return this;
502                                 },
503
504                                 // Cancel the request
505                                 abort: function( statusText ) {
506                                         var finalText = statusText || strAbort;
507                                         if ( transport ) {
508                                                 transport.abort( finalText );
509                                         }
510                                         done( 0, finalText );
511                                         return this;
512                                 }
513                         };
514
515                 // Attach deferreds
516                 deferred.promise( jqXHR ).complete = completeDeferred.add;
517                 jqXHR.success = jqXHR.done;
518                 jqXHR.error = jqXHR.fail;
519
520                 // Remove hash character (#7531: and string promotion)
521                 // Add protocol if not provided (prefilters might expect it)
522                 // Handle falsy url in the settings object (#10093: consistency with old signature)
523                 // We also use the url parameter if available
524                 s.url = ( ( url || s.url || location.href ) + "" ).replace( rhash, "" )
525                         .replace( rprotocol, location.protocol + "//" );
526
527                 // Alias method option to type as per ticket #12004
528                 s.type = options.method || options.type || s.method || s.type;
529
530                 // Extract dataTypes list
531                 s.dataTypes = jQuery.trim( s.dataType || "*" ).toLowerCase().match( rnotwhite ) || [ "" ];
532
533                 // A cross-domain request is in order when the origin doesn't match the current origin.
534                 if ( s.crossDomain == null ) {
535                         urlAnchor = document.createElement( "a" );
536
537                         // Support: IE8-11+
538                         // IE throws exception if url is malformed, e.g. http://example.com:80x/
539                         try {
540                                 urlAnchor.href = s.url;
541
542                                 // Support: IE8-11+
543                                 // Anchor's host property isn't correctly set when s.url is relative
544                                 urlAnchor.href = urlAnchor.href;
545                                 s.crossDomain = originAnchor.protocol + "//" + originAnchor.host !==
546                                         urlAnchor.protocol + "//" + urlAnchor.host;
547                         } catch ( e ) {
548
549                                 // If there is an error parsing the URL, assume it is crossDomain,
550                                 // it can be rejected by the transport if it is invalid
551                                 s.crossDomain = true;
552                         }
553                 }
554
555                 // Convert data if not already a string
556                 if ( s.data && s.processData && typeof s.data !== "string" ) {
557                         s.data = jQuery.param( s.data, s.traditional );
558                 }
559
560                 // Apply prefilters
561                 inspectPrefiltersOrTransports( prefilters, s, options, jqXHR );
562
563                 // If request was aborted inside a prefilter, stop there
564                 if ( state === 2 ) {
565                         return jqXHR;
566                 }
567
568                 // We can fire global events as of now if asked to
569                 // Don't fire events if jQuery.event is undefined in an AMD-usage scenario (#15118)
570                 fireGlobals = jQuery.event && s.global;
571
572                 // Watch for a new set of requests
573                 if ( fireGlobals && jQuery.active++ === 0 ) {
574                         jQuery.event.trigger( "ajaxStart" );
575                 }
576
577                 // Uppercase the type
578                 s.type = s.type.toUpperCase();
579
580                 // Determine if request has content
581                 s.hasContent = !rnoContent.test( s.type );
582
583                 // Save the URL in case we're toying with the If-Modified-Since
584                 // and/or If-None-Match header later on
585                 cacheURL = s.url;
586
587                 // More options handling for requests with no content
588                 if ( !s.hasContent ) {
589
590                         // If data is available, append data to url
591                         if ( s.data ) {
592                                 cacheURL = ( s.url += ( rquery.test( cacheURL ) ? "&" : "?" ) + s.data );
593
594                                 // #9682: remove data so that it's not used in an eventual retry
595                                 delete s.data;
596                         }
597
598                         // Add anti-cache in url if needed
599                         if ( s.cache === false ) {
600                                 s.url = rts.test( cacheURL ) ?
601
602                                         // If there is already a '_' parameter, set its value
603                                         cacheURL.replace( rts, "$1_=" + nonce++ ) :
604
605                                         // Otherwise add one to the end
606                                         cacheURL + ( rquery.test( cacheURL ) ? "&" : "?" ) + "_=" + nonce++;
607                         }
608                 }
609
610                 // Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
611                 if ( s.ifModified ) {
612                         if ( jQuery.lastModified[ cacheURL ] ) {
613                                 jqXHR.setRequestHeader( "If-Modified-Since", jQuery.lastModified[ cacheURL ] );
614                         }
615                         if ( jQuery.etag[ cacheURL ] ) {
616                                 jqXHR.setRequestHeader( "If-None-Match", jQuery.etag[ cacheURL ] );
617                         }
618                 }
619
620                 // Set the correct header, if data is being sent
621                 if ( s.data && s.hasContent && s.contentType !== false || options.contentType ) {
622                         jqXHR.setRequestHeader( "Content-Type", s.contentType );
623                 }
624
625                 // Set the Accepts header for the server, depending on the dataType
626                 jqXHR.setRequestHeader(
627                         "Accept",
628                         s.dataTypes[ 0 ] && s.accepts[ s.dataTypes[ 0 ] ] ?
629                                 s.accepts[ s.dataTypes[ 0 ] ] +
630                                         ( s.dataTypes[ 0 ] !== "*" ? ", " + allTypes + "; q=0.01" : "" ) :
631                                 s.accepts[ "*" ]
632                 );
633
634                 // Check for headers option
635                 for ( i in s.headers ) {
636                         jqXHR.setRequestHeader( i, s.headers[ i ] );
637                 }
638
639                 // Allow custom headers/mimetypes and early abort
640                 if ( s.beforeSend &&
641                         ( s.beforeSend.call( callbackContext, jqXHR, s ) === false || state === 2 ) ) {
642
643                         // Abort if not done already and return
644                         return jqXHR.abort();
645                 }
646
647                 // Aborting is no longer a cancellation
648                 strAbort = "abort";
649
650                 // Install callbacks on deferreds
651                 for ( i in { success: 1, error: 1, complete: 1 } ) {
652                         jqXHR[ i ]( s[ i ] );
653                 }
654
655                 // Get transport
656                 transport = inspectPrefiltersOrTransports( transports, s, options, jqXHR );
657
658                 // If no transport, we auto-abort
659                 if ( !transport ) {
660                         done( -1, "No Transport" );
661                 } else {
662                         jqXHR.readyState = 1;
663
664                         // Send global event
665                         if ( fireGlobals ) {
666                                 globalEventContext.trigger( "ajaxSend", [ jqXHR, s ] );
667                         }
668
669                         // If request was aborted inside ajaxSend, stop there
670                         if ( state === 2 ) {
671                                 return jqXHR;
672                         }
673
674                         // Timeout
675                         if ( s.async && s.timeout > 0 ) {
676                                 timeoutTimer = window.setTimeout( function() {
677                                         jqXHR.abort( "timeout" );
678                                 }, s.timeout );
679                         }
680
681                         try {
682                                 state = 1;
683                                 transport.send( requestHeaders, done );
684                         } catch ( e ) {
685
686                                 // Propagate exception as error if not done
687                                 if ( state < 2 ) {
688                                         done( -1, e );
689
690                                 // Simply rethrow otherwise
691                                 } else {
692                                         throw e;
693                                 }
694                         }
695                 }
696
697                 // Callback for when everything is done
698                 function done( status, nativeStatusText, responses, headers ) {
699                         var isSuccess, success, error, response, modified,
700                                 statusText = nativeStatusText;
701
702                         // Called once
703                         if ( state === 2 ) {
704                                 return;
705                         }
706
707                         // State is "done" now
708                         state = 2;
709
710                         // Clear timeout if it exists
711                         if ( timeoutTimer ) {
712                                 window.clearTimeout( timeoutTimer );
713                         }
714
715                         // Dereference transport for early garbage collection
716                         // (no matter how long the jqXHR object will be used)
717                         transport = undefined;
718
719                         // Cache response headers
720                         responseHeadersString = headers || "";
721
722                         // Set readyState
723                         jqXHR.readyState = status > 0 ? 4 : 0;
724
725                         // Determine if successful
726                         isSuccess = status >= 200 && status < 300 || status === 304;
727
728                         // Get response data
729                         if ( responses ) {
730                                 response = ajaxHandleResponses( s, jqXHR, responses );
731                         }
732
733                         // Convert no matter what (that way responseXXX fields are always set)
734                         response = ajaxConvert( s, response, jqXHR, isSuccess );
735
736                         // If successful, handle type chaining
737                         if ( isSuccess ) {
738
739                                 // Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
740                                 if ( s.ifModified ) {
741                                         modified = jqXHR.getResponseHeader( "Last-Modified" );
742                                         if ( modified ) {
743                                                 jQuery.lastModified[ cacheURL ] = modified;
744                                         }
745                                         modified = jqXHR.getResponseHeader( "etag" );
746                                         if ( modified ) {
747                                                 jQuery.etag[ cacheURL ] = modified;
748                                         }
749                                 }
750
751                                 // if no content
752                                 if ( status === 204 || s.type === "HEAD" ) {
753                                         statusText = "nocontent";
754
755                                 // if not modified
756                                 } else if ( status === 304 ) {
757                                         statusText = "notmodified";
758
759                                 // If we have data, let's convert it
760                                 } else {
761                                         statusText = response.state;
762                                         success = response.data;
763                                         error = response.error;
764                                         isSuccess = !error;
765                                 }
766                         } else {
767
768                                 // Extract error from statusText and normalize for non-aborts
769                                 error = statusText;
770                                 if ( status || !statusText ) {
771                                         statusText = "error";
772                                         if ( status < 0 ) {
773                                                 status = 0;
774                                         }
775                                 }
776                         }
777
778                         // Set data for the fake xhr object
779                         jqXHR.status = status;
780                         jqXHR.statusText = ( nativeStatusText || statusText ) + "";
781
782                         // Success/Error
783                         if ( isSuccess ) {
784                                 deferred.resolveWith( callbackContext, [ success, statusText, jqXHR ] );
785                         } else {
786                                 deferred.rejectWith( callbackContext, [ jqXHR, statusText, error ] );
787                         }
788
789                         // Status-dependent callbacks
790                         jqXHR.statusCode( statusCode );
791                         statusCode = undefined;
792
793                         if ( fireGlobals ) {
794                                 globalEventContext.trigger( isSuccess ? "ajaxSuccess" : "ajaxError",
795                                         [ jqXHR, s, isSuccess ? success : error ] );
796                         }
797
798                         // Complete
799                         completeDeferred.fireWith( callbackContext, [ jqXHR, statusText ] );
800
801                         if ( fireGlobals ) {
802                                 globalEventContext.trigger( "ajaxComplete", [ jqXHR, s ] );
803
804                                 // Handle the global AJAX counter
805                                 if ( !( --jQuery.active ) ) {
806                                         jQuery.event.trigger( "ajaxStop" );
807                                 }
808                         }
809                 }
810
811                 return jqXHR;
812         },
813
814         getJSON: function( url, data, callback ) {
815                 return jQuery.get( url, data, callback, "json" );
816         },
817
818         getScript: function( url, callback ) {
819                 return jQuery.get( url, undefined, callback, "script" );
820         }
821 } );
822
823 jQuery.each( [ "get", "post" ], function( i, method ) {
824         jQuery[ method ] = function( url, data, callback, type ) {
825
826                 // Shift arguments if data argument was omitted
827                 if ( jQuery.isFunction( data ) ) {
828                         type = type || callback;
829                         callback = data;
830                         data = undefined;
831                 }
832
833                 // The url can be an options object (which then must have .url)
834                 return jQuery.ajax( jQuery.extend( {
835                         url: url,
836                         type: method,
837                         dataType: type,
838                         data: data,
839                         success: callback
840                 }, jQuery.isPlainObject( url ) && url ) );
841         };
842 } );
843
844 return jQuery;
845 } );