From bfc61b879e9e94ef7c6b31919b7f287ffdf180a8 Mon Sep 17 00:00:00 2001 From: byroot Date: Thu, 24 Jan 2013 02:33:17 +0100 Subject: [PATCH] Don't try and convert data for 204 No Content responses. Fixes #13292. Fixes #13261. --- src/ajax.js | 11 ++++++++--- test/data/nocontent.php | 5 +++++ test/unit/ajax.js | 20 ++++++++++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 test/data/nocontent.php diff --git a/src/ajax.js b/src/ajax.js index 6dd34a732..a7508e972 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -624,12 +624,17 @@ jQuery.extend({ } } - // If not modified - if ( status === 304 ) { + // if no content + if ( status === 204 ) { + isSuccess = true; + statusText = "nocontent"; + + // if not modified + } else if ( status === 304 ) { isSuccess = true; statusText = "notmodified"; - // If we have data + // If we have data, let's convert it } else { isSuccess = ajaxConvert( s, response ); statusText = isSuccess.state; diff --git a/test/data/nocontent.php b/test/data/nocontent.php new file mode 100644 index 000000000..9c8431bd7 --- /dev/null +++ b/test/data/nocontent.php @@ -0,0 +1,5 @@ + \ No newline at end of file diff --git a/test/unit/ajax.js b/test/unit/ajax.js index 7bc48c997..e5e82f977 100644 --- a/test/unit/ajax.js +++ b/test/unit/ajax.js @@ -1456,6 +1456,26 @@ module( "ajax", { strictEqual( ajaxXML.find("tab").length, 3, "Parsed node was added properly" ); } }); + + ajaxTest( "#13292 - jQuery.ajax() - converter is bypassed for 204 requests", 3, { + url: "data/nocontent.php", + dataType: "testing", + converters: { + "* testing": function() { + throw "converter was called"; + } + }, + success: function( data, status, jqXHR ) { + strictEqual( jqXHR.status, 204, "status code is 204" ); + strictEqual( status, "nocontent", "status text is 'nocontent'" ); + 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() -- 2.39.5