Script transport now uses ajaxSetup to define script dataType.
[jquery.git] / src / ajax.js
index 744476f..968c67c 100644 (file)
@@ -10,7 +10,8 @@ var r20 = /%20/g,
        rscript = /<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,
        rselectTextarea = /^(?:select|textarea)/i,
        rts = /([?&])_=[^&]*/,
-       rurl = /^(\w+:)?\/\/([^\/?#]+)/,
+       rurl = /^(\w+:)?\/\/([^\/?#:]+)(?::(\d+))?/,
+       rCRLF = /\r?\n/g,
 
        // Slice function
        sliceFunc = Array.prototype.slice,
@@ -60,26 +61,34 @@ jQuery.fn.extend({
                        type: type,
                        dataType: "html",
                        data: params,
-                       complete: function( res, status ) {
+                       // Complete callback (responseText is used internally)
+                       complete: function( jXHR, status, responseText ) {
+                               // Store the response as specified by the jXHR object
+                               responseText = jXHR.responseText;
                                // If successful, inject the HTML into all the matched elements
-                               if ( status === "success" || status === "notmodified" ) {
+                               if ( jXHR.isResolved() ) {
+                                       // #4825: Get the actual response in case
+                                       // a dataFilter is present in ajaxSettings
+                                       jXHR.done(function( r ) {
+                                               responseText = r;
+                                       });
                                        // See if a selector was specified
                                        self.html( selector ?
                                                // Create a dummy div to hold the results
                                                jQuery("<div>")
                                                        // inject the contents of the document in, removing the scripts
                                                        // to avoid any 'Permission Denied' errors in IE
-                                                       .append(res.responseText.replace(rscript, ""))
+                                                       .append(responseText.replace(rscript, ""))
 
                                                        // Locate the specified elements
                                                        .find(selector) :
 
                                                // If not, just inject the full result
-                                               res.responseText );
+                                               responseText );
                                }
 
                                if ( callback ) {
-                                       self.each( callback, [res.responseText, status, res] );
+                                       self.each( callback, [responseText, status, jXHR] );
                                }
                        }
                });
@@ -107,9 +116,9 @@ jQuery.fn.extend({
                                null :
                                jQuery.isArray(val) ?
                                        jQuery.map( val, function(val, i){
-                                               return {name: elem.name, value: val.replace(/\r?\n/g, "\r\n")};
+                                               return { name: elem.name, value: val.replace(rCRLF, "\r\n") };
                                        }) :
-                                       {name: elem.name, value: val.replace(/\r?\n/g, "\r\n")};
+                                       { name: elem.name, value: val.replace(rCRLF, "\r\n") };
                }).get();
        }
 });
@@ -151,7 +160,7 @@ jQuery.extend({
        },
 
        ajaxSetup: function( settings ) {
-               jQuery.extend( jQuery.ajaxSettings, settings );
+               jQuery.extend( true, jQuery.ajaxSettings, settings );
        },
 
        ajaxSettings: {
@@ -520,21 +529,29 @@ jQuery.extend({
                // Determine if a cross-domain request is in order
                var parts = rurl.exec( s.url.toLowerCase() ),
                        loc = location;
-               s.crossDomain = !!( parts && ( parts[ 1 ] && parts[ 1 ] != loc.protocol || parts[ 2 ] != loc.host ) );
+
+               if ( ! s.crossDomain ) {
+                       s.crossDomain = !!(
+                                       parts &&
+                                       ( parts[ 1 ] && parts[ 1 ] != loc.protocol ||
+                                               parts[ 2 ] != loc.hostname ||
+                                               ( parts[ 3 ] || 80 ) != ( loc.port || 80 ) )
+                       );
+               }
 
                // Convert data if not already a string
                if ( s.data && s.processData && typeof s.data != "string" ) {
                        s.data = jQuery.param( s.data , s.traditional );
                }
 
+               // Get transport
+               transport = jQuery.ajax.prefilter( s , options ).transport( s );
+
                // Watch for a new set of requests
                if ( s.global && jQuery.active++ === 0 ) {
                        jQuery.event.trigger( "ajaxStart" );
                }
 
-               // Get transport
-               transport = jQuery.ajax.prefilter( s ).transport( s );
-
                // If no transport, we auto-abort
                if ( ! transport ) {