Commit c4e65323 authored by Dave Methvin's avatar Dave Methvin Committed by jeresig

Make sure that requests without a body don't set contentType, and a...

Make sure that requests without a body don't set contentType, and a zero-length body is sent rather than null. Possible fix for #6811 and #6674.
parent 1130beb7
...@@ -4,6 +4,7 @@ var jsc = jQuery.now(), ...@@ -4,6 +4,7 @@ var jsc = jQuery.now(),
rscript = /<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, rscript = /<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,
rselectTextarea = /^(?:select|textarea)/i, rselectTextarea = /^(?:select|textarea)/i,
rinput = /^(?:color|date|datetime|email|hidden|month|number|password|range|search|tel|text|time|url|week)$/i, rinput = /^(?:color|date|datetime|email|hidden|month|number|password|range|search|tel|text|time|url|week)$/i,
rnoContent = /^(?:GET|HEAD|DELETE)$/,
rbracket = /\[\]$/, rbracket = /\[\]$/,
jsre = /\=\?(&|$)/, jsre = /\=\?(&|$)/,
rquery = /\?/, rquery = /\?/,
...@@ -204,7 +205,7 @@ jQuery.extend({ ...@@ -204,7 +205,7 @@ jQuery.extend({
ajax: function( origSettings ) { ajax: function( origSettings ) {
var s = jQuery.extend(true, {}, jQuery.ajaxSettings, 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.url = s.url.replace( rhash, "" );
...@@ -355,8 +356,8 @@ jQuery.extend({ ...@@ -355,8 +356,8 @@ jQuery.extend({
// Need an extra try/catch for cross domain requests in Firefox 3 // Need an extra try/catch for cross domain requests in Firefox 3
try { try {
// Set the correct header, if data is being sent // Set content-type if data specified and content-body is valid for this type
if ( s.data || origSettings && origSettings.contentType ) { if ( (s.data != null && !noContent) || (origSettings && origSettings.contentType) ) {
xhr.setRequestHeader("Content-Type", s.contentType); xhr.setRequestHeader("Content-Type", s.contentType);
} }
...@@ -491,7 +492,7 @@ jQuery.extend({ ...@@ -491,7 +492,7 @@ jQuery.extend({
// Send the data // Send the data
try { try {
xhr.send( (type !== "GET" && s.data) || null ); xhr.send( noContent || s.data == null ? null : s.data );
} catch( sendError ) { } catch( sendError ) {
jQuery.ajax.handleError( s, xhr, null, sendError ); jQuery.ajax.handleError( s, xhr, null, sendError );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment