From: Jörn Zaefferer Date: Tue, 6 May 2008 22:21:43 +0000 (+0000) Subject: jquery ajax: support for dynamic data arguments, see #2806; added test/data/echoQuery... X-Git-Url: http://git.asbjorn.biz/?p=jquery.git;a=commitdiff_plain;h=46931d3146b454298231fc80a6c2d3894b125fde jquery ajax: support for dynamic data arguments, see #2806; added test/data/echoQuery.php for easier testing of sent query strings --- diff --git a/src/ajax.js b/src/ajax.js index b089f22..b90ca16 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 0000000..b72f329 --- /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 c8bf2ce..a5891c5 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(); + } + }) +}); + } //}