]> source.dussan.org Git - jquery.git/commitdiff
Don't try and convert data for 204 No Content responses. Fixes #13292. Fixes #13261.
authorbyroot <jean.boussier@gmail.com>
Thu, 24 Jan 2013 01:33:17 +0000 (02:33 +0100)
committerjaubourg <j@ubourg.net>
Thu, 24 Jan 2013 01:35:07 +0000 (02:35 +0100)
src/ajax.js
test/data/nocontent.php [new file with mode: 0644]
test/unit/ajax.js

index 6dd34a7326887dc156ac29dfa4aa3613912ad588..a7508e9721da92558e9cca4e324ae6b905f54733 100644 (file)
@@ -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 (file)
index 0000000..9c8431b
--- /dev/null
@@ -0,0 +1,5 @@
+<?php
+
+header('HTTP/1.0 204 No Content');
+
+?>
\ No newline at end of file
index 86d1b191247a5ab16b7c7f5d926e669534011834..b3734e38b25e60bd60bb8050760f2a344086a21f 100644 (file)
@@ -1498,6 +1498,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()