Skip to content

Commit

Permalink
Make sure that requests without a body don't set contentType, and a z…
Browse files Browse the repository at this point in the history
…ero-length body is sent rather than null. Possible fix for #6811 and #6674.
  • Loading branch information
dmethvin authored and jeresig committed Sep 24, 2010
1 parent 1130beb commit c4e6532
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/ajax.js
Expand Up @@ -4,6 +4,7 @@ var jsc = jQuery.now(),
rscript = /<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/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 = /\?/,
Expand Down Expand Up @@ -204,7 +205,7 @@ 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, "" );

Expand Down Expand Up @@ -355,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);
}

Expand Down Expand Up @@ -491,7 +492,7 @@ 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, sendError );
Expand Down

0 comments on commit c4e6532

Please sign in to comment.