X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fajax.js;h=82c499b6498d82c427a591f4be9f8b4c4280db6b;hb=0c51e9d55f39366cab14719b80cb7e989c716351;hp=d78542d02ebe4dc4ba78aea62891d05ca589a901;hpb=e56de77df90e50b9999a02e57241b1cf498b0fe4;p=jquery.git diff --git a/src/ajax.js b/src/ajax.js index d78542d..82c499b 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -10,7 +10,8 @@ var r20 = /%20/g, rscript = /)<[^<]*)*<\/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("
") // 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(); } }); @@ -464,6 +473,11 @@ jQuery.extend({ } else { // if not success, mark it as an error error = error || statusText; + + // Set responseText if needed + if ( response ) { + jXHR.responseText = response; + } } // Set data for the fake xhr object @@ -496,9 +510,9 @@ jQuery.extend({ // Attach deferreds deferred.promise( jXHR ); - jXHR.success = jXHR.complete; + jXHR.success = jXHR.done; jXHR.error = jXHR.fail; - jXHR.complete = completeDeferred.complete; + jXHR.complete = completeDeferred.done; // Remove hash character (#7531: and string promotion) s.url = ( "" + s.url ).replace( rhash , "" ); @@ -515,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 ) { @@ -559,7 +581,7 @@ jQuery.extend({ } // Set the correct header, if data is being sent - if ( ( s.data && s.hasContent ) || options.contentType ) { + if ( s.data && s.hasContent && s.contentType !== false || options.contentType ) { requestHeaders[ "content-type" ] = s.contentType; }