From a2cd89a795067d67d8212a4571991e5d2fb0ea8f Mon Sep 17 00:00:00 2001 From: Julian Aubourg Date: Thu, 23 May 2013 02:11:37 +0200 Subject: [PATCH] Handles HEAD requests as if they always were 204. Fixes #13922. --- src/ajax.js | 2 +- test/unit/ajax.js | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/ajax.js b/src/ajax.js index d0a8a4f12..8facc17fe 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -614,7 +614,7 @@ jQuery.extend({ } // if no content - if ( status === 204 ) { + if ( status === 204 || s.type === "HEAD" ) { statusText = "nocontent"; // if not modified diff --git a/test/unit/ajax.js b/test/unit/ajax.js index 2dd74c384..761885ccb 100644 --- a/test/unit/ajax.js +++ b/test/unit/ajax.js @@ -1499,6 +1499,29 @@ module( "ajax", { } }); + ajaxTest( "#13922 - jQuery.ajax() - converter is bypassed for HEAD requests", 3, { + url: "data/json.php", + method: "HEAD", + data: { + header: "yes" + }, + converters: { + "text json": function() { + throw "converter was called"; + } + }, + success: function( data, status ) { + ok( true, "success" ); + strictEqual( status, "nocontent", "data is undefined" ); + strictEqual( data, undefined, "data is undefined" ); + }, + error: function( _, status, error ) { + ok( false, "error" ); + strictEqual( status, "parsererror", "Parser Error" ); + strictEqual( error, "converter was called", "Converter was called" ); + } + } ); + //----------- jQuery.ajaxPrefilter() ajaxTest( "jQuery.ajaxPrefilter() - abort", 1, { -- 2.39.5