Fixing request data param issue. Thanks to mislav for the patch. Fixes #5123.
authorjeresig <jeresig@gmail.com>
Tue, 15 Jun 2010 03:08:28 +0000 (23:08 -0400)
committerjeresig <jeresig@gmail.com>
Tue, 15 Jun 2010 03:08:28 +0000 (23:08 -0400)
src/ajax.js
test/data/echoData.php [new file with mode: 0644]
test/unit/ajax.js

index 47f243e..2c4f13c 100644 (file)
@@ -484,7 +484,7 @@ jQuery.extend({
 
                // Send the data
                try {
-                       xhr.send( type === "POST" || type === "PUT" || type === "DELETE" ? s.data : null );
+                       xhr.send( (type !== "GET" && s.data) || null );
 
                } catch( sendError ) {
                        jQuery.ajax.handleError( s, xhr, null, e );
diff --git a/test/data/echoData.php b/test/data/echoData.php
new file mode 100644 (file)
index 0000000..a37ba51
--- /dev/null
@@ -0,0 +1 @@
+<?php echo file_get_contents('php://input'); ?>
index fe44ba3..8e3c4b6 100644 (file)
@@ -1163,6 +1163,19 @@ test("data option: evaluate function values (#2806)", function() {
        })
 });
 
+test("data option: empty bodies for non-GET requests", function() {
+       stop();
+       jQuery.ajax({
+               url: "data/echoData.php",
+               data: undefined,
+               type: "post",
+               success: function(result) {
+                       equals( result, "" );
+                       start();
+               }
+       })
+});
+
 test("jQuery.ajax - If-Modified-Since support", function() {
        expect( 3 );