From 46931d3146b454298231fc80a6c2d3894b125fde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Zaefferer?= Date: Tue, 6 May 2008 22:21:43 +0000 Subject: [PATCH] jquery ajax: support for dynamic data arguments, see #2806; added test/data/echoQuery.php for easier testing of sent query strings --- src/ajax.js | 2 +- test/data/echoQuery.php | 1 + test/unit/ajax.js | 16 ++++++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 test/data/echoQuery.php diff --git a/src/ajax.js b/src/ajax.js index b089f22c2..b90ca16cb 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -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 index 000000000..b72f329c9 --- /dev/null +++ b/test/data/echoQuery.php @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/unit/ajax.js b/test/unit/ajax.js index c8bf2ce4b..a5891c53e 100644 --- a/test/unit/ajax.js +++ b/test/unit/ajax.js @@ -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(); + } + }) +}); + } //}