]> source.dussan.org Git - jquery.git/commitdiff
jquery ajax: support for dynamic data arguments, see #2806; added test/data/echoQuery...
authorJörn Zaefferer <joern.zaefferer@gmail.com>
Tue, 6 May 2008 22:21:43 +0000 (22:21 +0000)
committerJörn Zaefferer <joern.zaefferer@gmail.com>
Tue, 6 May 2008 22:21:43 +0000 (22:21 +0000)
src/ajax.js
test/data/echoQuery.php [new file with mode: 0644]
test/unit/ajax.js

index b089f22c29cad7858a7b576854dd62a9e2960fd8..b90ca16cbc4076b69b0811afec201b96cc890a9e 100644 (file)
@@ -489,7 +489,7 @@ jQuery.extend({
                                                s.push( encodeURIComponent(j) + "=" + encodeURIComponent( this ) );
                                        });
                                else
-                                       s.push( encodeURIComponent(j) + "=" + encodeURIComponent( a[j] ) );
+                                       s.push( encodeURIComponent(j) + "=" + encodeURIComponent( jQuery.isFunction(a[j]) ? a[j]() : a[j] ) );
 
                // Return the resulting serialization
                return s.join("&").replace(/%20/g, "+");
diff --git a/test/data/echoQuery.php b/test/data/echoQuery.php
new file mode 100644 (file)
index 0000000..b72f329
--- /dev/null
@@ -0,0 +1 @@
+<?php echo $_SERVER['QUERY_STRING']; ?>
\ No newline at end of file
index c8bf2ce4bd93e506215dc3669c52d943fec278d9..a5891c53efe2ede1c77f13b9063d64dff93bc486 100644 (file)
@@ -811,6 +811,22 @@ test("custom timeout does not set error message when timeout occurs, see #970",
        });
 });
 
+test("data option: evaluate function values (#2806)", function() {
+       stop();
+       $.ajax({
+               url: "data/echoQuery.php",
+               data: {
+                       key: function() {
+                               return "value";
+                       }
+               },
+               success: function(result) {
+                       equals( result, "key=value" );
+                       start();
+               }
+       })
+});
+
 }
 
 //}