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, needs testing from someone who could repro the original problem.
  • Loading branch information
dmethvin committed Sep 15, 2010
1 parent 722af53 commit dde3cdc
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var jsc = jQuery.now(),
rscript = /<script(.|\s)*?\/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$/,
jsre = /\=\?(&|$)/,
rquery = /\?/,
rts = /(\?|&)_=.*?(&|$)/,
Expand Down Expand Up @@ -202,7 +203,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);

// Use original (not extended) context object if it was provided
s.context = ( origSettings && origSettings.context !== undefined )? origSettings.context : s;
Expand Down Expand Up @@ -351,8 +352,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 || type === "POST" || 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 @@ -487,7 +488,7 @@ jQuery.extend({

// Send the data
try {
xhr.send( (type !== "GET" && s.data) || null );
xhr.send( (noContent || s.data == null)? null : s.data );

} catch( e ) {
jQuery.ajax.handleError( s, xhr, null, e );
Expand Down

0 comments on commit dde3cdc

Please sign in to comment.