New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include array indexes in $.param() #749

wants to merge 2 commits into
base: master


None yet
2 participants

levic commented Apr 29, 2013

#208 rewrote support for key[] support inside $.param(), but it doesn't work if you have objects inside arrays:

Consider the case of:


It is ambiguous whether the var[][b] belongs to the [a] object, the [c] object or is an object on its own. PHP at least treats it as a totally new object which means it is impossible to have an array with objects with multiple values. jQuery gets around this by always including the array index, so the above example would become (assuming the [b] belonged to the same object as the [a]):


Demonstration fiddles: (jquery) (zepto)

Attached patch adds the array index back in & updates test cases. traditional argument passing doesn't change, as mentioned in #208 it can't handle nested items anyway.

Levi Cameron
Include array index when serializing nested arrays
Needed for jquery & PHP compatibility

This comment has been minimized.


mislav commented Apr 29, 2013

It doesn't seem like jQuery always includes the array index. Only when the value is an object. Could you look into that detail?

Levi Cameron
Modify .serialize() to more closely match jquery behaviour
For arrays containing scalars, query does not include the final array index

This comment has been minimized.

levic commented May 1, 2013

Have updated and added a new test case based on (was able to pass the original test cases when I still had code that wasn't consistent with jquery)

In the situation of x : [ [ [ 5 ] ] ](ie if the tree contains only scalars or arrays with 1 element) you could theoretically generate x[][][]=5 but jquery doesn't go in for the extra complexity of doing that so I didn't even try.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment