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 b089f22..b90ca16 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 c8bf2ce..a5891c5 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();
+               }
+       })
+});
+
 }
 
 //}