Side navigation
#2868 closed enhancement (fixed)
Opened May 14, 2008 05:51PM UTC
Closed June 15, 2010 02:26AM UTC
Make $.param recursive
Reported by: | the_undefined | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | 1.2.4 |
Component: | ajax | Version: | 1.2.3 |
Keywords: | param recursive http serialize | Cc: | the_undefined |
Blocked by: | Blocking: |
Description
I think it would be great if the $.param function was recursive. The code for this could look similar to that (this is what I use right now):
$.httpSerialize = function(items, parentName) { var serializedItems = [], serialize = arguments.callee, encodeItem = function(key, value) { if (value === null || typeof value == 'undefined') return value; if (value.constructor == Array) {return serialize(value, key);} return (value.constructor == Object) ? serialize(value, key) : (value === true || value === false) ? key+"="+new Number(value) : key+"="+encodeURIComponent(value); }; if (items.constructor == Array) { parentName = parentName || 'item'; for (var i = 0; i < items.length; i++) { var key = parentName+'['+i+']', value = items[i]; serializedItems.push(encodeItem(key, value)); } } else { parentName = parentName || ''; for (var key in items) { var value = items[key]; if (parentName) { serializedItems.push(encodeItem(parentName+'['+encodeURIComponent(key)+']', value)); } else { serializedItems.push(encodeItem(encodeURIComponent(key), value)); } } } return serializedItems.join("&"); };
If there is interest I can provide a patch with a refactored and cleaned up version of the above. I pretty much find myself needing a recursive param version every time I work on a complex app.
Attachments (0)
Change History (4)
Changed May 15, 2008 08:41AM UTC by comment:1
Changed May 15, 2008 09:09PM UTC by comment:2
component: | core → ajax |
---|
Changed July 01, 2008 07:07AM UTC by comment:3
Hey, is there no interest in this or is just nobody having the time? I can come up with a patch for this if thats what needs to be done ; )
Changed June 15, 2010 02:26AM UTC by comment:4
resolution: | → fixed |
---|---|
status: | new → closed |
Implemented via the ajax
traditionalproperty.
Oddly enough I did this tonight as well. It's nice to know that I'm not the only person out there who wants this.
http://dev.jquery.com/ticket/2871
http://the-erm.com/~erm/player2/mda.php // here's the demo.