Change embedded regexp to a variable (for #6876).
[jquery.git] / src / ajax.js
index e910aa5..d570fcc 100644 (file)
@@ -11,6 +11,7 @@ var r20 = /%20/g,
        rselectTextarea = /^(?:select|textarea)/i,
        rts = /([?&])_=[^&]*/,
        rurl = /^(\w+:)?\/\/([^\/?#:]+)(?::(\d+))?/,
+       rCRLF = /\r?\n/g,
 
        // Slice function
        sliceFunc = Array.prototype.slice,
@@ -107,9 +108,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();
        }
 });
@@ -520,12 +521,15 @@ 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.hostname ||
-                                       ( parts[ 3 ] || 80 ) != ( loc.port || 80 ) )
-               );
+
+               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" ) {
@@ -533,7 +537,7 @@ jQuery.extend({
                }
 
                // Get transport
-               transport = jQuery.ajax.prefilter( s ).transport( s );
+               transport = jQuery.ajax.prefilter( s , options ).transport( s );
 
                // Watch for a new set of requests
                if ( s.global && jQuery.active++ === 0 ) {