X-Git-Url: http://git.asbjorn.it/?a=blobdiff_plain;f=src%2Fajax.js;h=31efc566f0a9f236df071333f9842484972baa0a;hb=8c41325a081f4009aa94748b9b6045e50a78422e;hp=897d424dad0881e4cd56eef099331548e6ca60f5;hpb=033a4c41e0440106a0dffdd7328cd8b04781b45d;p=jquery.git diff --git a/src/ajax.js b/src/ajax.js index 897d424..31efc56 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -4,10 +4,11 @@ var jsc = jQuery.now(), rscript = /)<[^<]*)*<\/script>/gi, rselectTextarea = /^(?:select|textarea)/i, rinput = /^(?:color|date|datetime|email|hidden|month|number|password|range|search|tel|text|time|url|week)$/i, + rnoContent = /^(?:GET|HEAD|DELETE)$/, rbracket = /\[\]$/, jsre = /\=\?(&|$)/, rquery = /\?/, - rts = /([?&])_=[^&]*(&?)/, + rts = /([?&])_=[^&]*/, rurl = /^(\w+:)?\/\/([^\/?#]+)/, r20 = /%20/g, rhash = /#.*$/, @@ -204,10 +205,12 @@ jQuery.extend({ ajax: function( origSettings ) { var s = jQuery.extend(true, {}, jQuery.ajaxSettings, origSettings), - jsonp, status, data, type = s.type.toUpperCase(); + jsonp, status, data, type = s.type.toUpperCase(), noContent = rnoContent.test(type); s.url = s.url.replace( rhash, "" ); - s.context = origSettings && origSettings.context || s; + + // Use original (not extended) context object if it was provided + s.context = origSettings && origSettings.context != null ? origSettings.context : s; // convert data if not already a string if ( s.data && s.processData && typeof s.data !== "string" ) { @@ -275,7 +278,7 @@ jQuery.extend({ var ts = jQuery.now(); // try replacing _= if it is there - var ret = s.url.replace(rts, "$1_=" + ts + "$2"); + var ret = s.url.replace(rts, "$1_=" + ts); // if nothing was replaced, add timestamp to the end s.url = ret + ((ret === s.url) ? (rquery.test(s.url) ? "&" : "?") + "_=" + ts : ""); @@ -300,10 +303,10 @@ jQuery.extend({ if ( s.dataType === "script" && type === "GET" && remote ) { var head = document.getElementsByTagName("head")[0] || document.documentElement; var script = document.createElement("script"); - script.src = s.url; if ( s.scriptCharset ) { script.charset = s.scriptCharset; } + script.src = s.url; // Handle Script loading if ( !jsonp ) { @@ -353,8 +356,8 @@ jQuery.extend({ // Need an extra try/catch for cross domain requests in Firefox 3 try { - // Set the correct header, if data is being sent - if ( s.data || origSettings && origSettings.contentType ) { + // Set content-type if data specified and content-body is valid for this type + if ( (s.data != null && !noContent) || (origSettings && origSettings.contentType) ) { xhr.setRequestHeader("Content-Type", s.contentType); } @@ -489,10 +492,10 @@ jQuery.extend({ // Send the data try { - xhr.send( (type !== "GET" && s.data) || null ); + xhr.send( noContent || s.data == null ? null : s.data ); } catch( sendError ) { - jQuery.ajax.handleError( s, xhr, null, e ); + jQuery.ajax.handleError( s, xhr, null, sendError ); // Fire the complete handlers jQuery.ajax.handleComplete( s, xhr, status, data );