Bug Tracker

Opened 15 years ago

Closed 13 years ago

#2868 closed enhancement (fixed)

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:


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.

Change History (4)

comment:1 Changed 15 years ago by the7erm

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.

comment:2 Changed 15 years ago by flesler

Component: coreajax

comment:3 Changed 15 years ago by the_undefine

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 ; )

comment:4 Changed 13 years ago by dmethvin

Resolution: fixed
Status: newclosed

Implemented via the ajax traditional property.

Note: See TracTickets for help on using tickets.