diff --git a/src/ajax.js b/src/ajax.js index d24ab5915..cbb49d8f3 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -349,6 +349,7 @@ $.param = function(obj, traditional){ var params = [] params.add = function(key, value) { + if ($.isFunction(value)) value = value() if (value == null) value = "" this.push(escape(key) + '=' + escape(value)) } diff --git a/test/ajax.html b/test/ajax.html index 70ff2ff9c..953d235f1 100644 --- a/test/ajax.html +++ b/test/ajax.html @@ -1450,6 +1450,13 @@

Zepto Ajax unit tests

decodeURIComponent($.param([{ name: "x", value: null }]))) }, + testParamFunctionValues: function(t) { + t.assertEqual("x=&a[b]=B", + decodeURIComponent($.param({ x: function(){}, a: { b: function(){ return "B" }}}))) + t.assertEqual("x=&a[b]=B", + decodeURIComponent($.param([{ name: "x", value: null }, { name: "a[b]", value: function(){ return "B" }}]))) + }, + testParamEscaping: function(t) { var result = $.param({ 'equation[1]': 'bananas+peaches=smoothie' }) t.assertEqual("equation%5B1%5D=bananas%2Bpeaches%3Dsmoothie", result)