X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fajax.js;h=ef0e1d8f92b5f2a6e82ce23a1e948b3b48a5bfdc;hb=42aa714fb79199ad0a45d5f76f43729b399b058a;hp=17cccf71922f64802de57fcc98b05b1d46f07824;hpb=c8c8f8458a579d8f87e7ee6b8e4510cc4e4445bb;p=jquery.git diff --git a/src/ajax.js b/src/ajax.js index 17cccf7..ef0e1d8 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -4,6 +4,7 @@ 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 = /\?/, @@ -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" ) { @@ -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 );