Permalink
Browse files

Don't try and convert data for 204 No Content responses. Fixes #13292…

…. Fixes #13261.
  • Loading branch information...
byroot authored and jaubourg committed Jan 24, 2013
1 parent caac041 commit bfc61b879e9e94ef7c6b31919b7f287ffdf180a8
Showing with 33 additions and 3 deletions.
  1. +8 −3 src/ajax.js
  2. +5 −0 test/data/nocontent.php
  3. +20 −0 test/unit/ajax.js
View
@@ -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;
View
@@ -0,0 +1,5 @@
+<?php
+
+header('HTTP/1.0 204 No Content');
+
+?>
View
@@ -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()

3 comments on commit bfc61b8

@gibson042

This comment has been minimized.

Show comment Hide comment
@gibson042

gibson042 Jan 25, 2013

Member

@jaubourg Does this need a cherry-pick to 1.9-stable, or is it related to 2.0-specific code?

Member

gibson042 replied Jan 25, 2013

@jaubourg Does this need a cherry-pick to 1.9-stable, or is it related to 2.0-specific code?

@jaubourg

This comment has been minimized.

Show comment Hide comment
@jaubourg

jaubourg Jan 25, 2013

Member

Unless I did something wrong, it's already in 1.9-stable... at least that's what the list here seems to indicate.

Member

jaubourg replied Jan 25, 2013

Unless I did something wrong, it's already in 1.9-stable... at least that's what the list here seems to indicate.

@gibson042

This comment has been minimized.

Show comment Hide comment
@gibson042

gibson042 Jan 25, 2013

Member

Just checking if you're paying attention. Heh-heh, yeah. Ahem.

Member

gibson042 replied Jan 25, 2013

Just checking if you're paying attention. Heh-heh, yeah. Ahem.

Please sign in to comment.