Skip to content
Permalink
Browse files

Allow DELETE requests to have a content body, and properly serialize …

…data to the url for HEAD requests. Fixes #7285.
  • Loading branch information
dmethvin authored and jeresig committed Oct 23, 2010
1 parent 974b5ae commit 09022e0b09db71259751e7146bb64727615028af
Showing with 30 additions and 4 deletions.
  1. +4 −4 src/ajax.js
  2. +26 −0 test/unit/ajax.js
@@ -4,7 +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)$/,
rnoContent = /^(?:GET|HEAD)$/,
rbracket = /\[\]$/,
jsre = /\=\?(&|$)/,
rquery = /\?/,
@@ -271,7 +271,7 @@ jQuery.extend({
s.cache = false;
}

if ( s.cache === false && type === "GET" ) {
if ( s.cache === false && noContent ) {
var ts = jQuery.now();

// try replacing _= if it is there
@@ -281,8 +281,8 @@ jQuery.extend({
s.url = ret + ((ret === s.url) ? (rquery.test(s.url) ? "&" : "?") + "_=" + ts : "");
}

// If data is available, append data to url for get requests
if ( s.data && type === "GET" ) {
// If data is available, append data to url for GET/HEAD requests
if ( s.data && noContent ) {
s.url += (rquery.test(s.url) ? "&" : "?") + s.data;
}

@@ -289,6 +289,32 @@ test("jQuery.ajax - xml: non-namespace elements inside namespaced elements", fun
});
});

test("jQuery.ajax - HEAD requests", function() {
expect(2);

stop();
jQuery.ajax({
url: url("data/name.html"),
type: "HEAD",
success: function(data, status, xhr){
var h = xhr.getAllResponseHeaders();
ok( /Date/i.test(h), 'No Date in HEAD response' );

jQuery.ajax({
url: url("data/name.html"),
data: { whip_it: "good" },
type: "HEAD",
success: function(data, status, xhr){
var h = xhr.getAllResponseHeaders();
ok( /Date/i.test(h), 'No Date in HEAD response with data' );
start();
}
});
}
});

});

test("jQuery.ajax - beforeSend", function() {
expect(1);
stop();

0 comments on commit 09022e0

Please sign in to comment.
You can’t perform that action at this time.