- // Matches an absolute URL, and saves the domain
- var parts = rurl.exec( s.url ),
- remote = parts && (parts[1] && parts[1].toLowerCase() !== location.protocol || parts[2].toLowerCase() !== location.host);
-
- // If we're requesting a remote document
- // and trying to load JSON or Script with a GET
- if ( s.dataType === "script" && type === "GET" && remote ) {
- var head = document.getElementsByTagName("head")[0] || document.documentElement;
- var script = document.createElement("script");
- if ( s.scriptCharset ) {
- script.charset = s.scriptCharset;
- }
- script.src = s.url;
-
- // Handle Script loading
- if ( !jsonp ) {
- var done = false;
-
- // Attach handlers for all browsers
- script.onload = script.onreadystatechange = function() {
- if ( !done && (!this.readyState ||
- this.readyState === "loaded" || this.readyState === "complete") ) {
- done = true;
- jQuery.handleSuccess( s, xhr, status, data );
- jQuery.handleComplete( s, xhr, status, data );
-
- // Handle memory leak in IE
- script.onload = script.onreadystatechange = null;
- if ( head && script.parentNode ) {
- head.removeChild( script );
+ // If we have data
+ } else {
+
+ statusText = "success";
+
+ // Chain data conversions and determine the final value
+ // (if an exception is thrown in the process, it'll be notified as an error)
+ try {
+
+ var i,
+ tmp,
+ // Current dataType
+ current,
+ // Previous dataType
+ prev,
+ // Conversion expression
+ conversion,
+ // Conversion function
+ conv,
+ // Conversion functions (when text is used in-between)
+ conv1,
+ conv2;
+
+ // For each dataType in the chain
+ for( i = 0 ; i < dataTypes.length ; i++ ) {
+
+ current = dataTypes[ i ];
+
+ // If a responseXXX field for this dataType exists
+ // and if it hasn't been set yet
+ responseField = responseFields[ current ];
+ if ( responseField && ! ( responseField in jXHR ) ) {
+ jXHR[ responseField ] = response;
+ }
+
+ // If this is not the first element
+ if ( i ) {
+
+ // Get the dataType to convert from
+ prev = dataTypes[ i - 1 ];
+
+ // If no auto and dataTypes are actually different
+ if ( prev !== "*" && current !== "*" && prev !== current ) {
+
+ // Get the converter
+ conversion = prev + " " + current;
+ conv = converters[ conversion ] || converters[ "* " + current ];
+
+ // If there is no direct converter, search transitively
+ if ( ! conv ) {
+ conv1 = conv2 = undefined;
+
+ for( conv1 in converters ) {
+ tmp = conv1.split( " " );
+ if ( tmp[ 0 ] === prev || tmp[ 0 ] === "*" ) {
+ conv2 = converters[ tmp[ 1 ] + " " + current ];
+ if ( conv2 ) {
+ conv1 = converters[ conv1 ];
+ if ( conv1 === true ) {
+ conv = conv2;
+ } else if ( conv2 === true ) {
+ conv = conv1;
+ }
+ break;
+ }
+ }
+ }
+ }
+ // If we found no converter, dispatch an error
+ if ( ! ( conv || conv1 && conv2 ) ) {
+ throw conversion;
+ }
+ // If found converter is not an equivalence
+ if ( conv !== true ) {
+ // Convert with 1 or 2 converters accordingly
+ response = conv ? conv( response ) : conv2( conv1( response ) );
+ }
+ }
+ // If it is the first element of the chain
+ // and we have a dataFilter
+ } else if ( s.dataFilter ) {
+ // Apply the dataFilter
+ response = s.dataFilter( response , current );
+ // Get dataTypes again in case the filter changed them
+ dataTypes = s.dataTypes;
+ }