Ticket #2871 (closed enhancement: fixed)
Multi dimentional array support for ajax posting.
| Reported by: | the7erm | Owned by: | |
|---|---|---|---|
| Priority: | major | Milestone: | 1.2.4 |
| Component: | ajax | Version: | 1.2.3 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
I don't know if you want to add this or not, but it's there if you want it.
I do a lot of multi dimensional work, and figured it'd be nice to have this ability in jquery.
Attachments
Change History
Changed 5 years ago by the7erm
-
attachment
jquery-nightly.js
added
Changed 5 years ago by the7erm
-
attachment
mda.php
added
php script used to toggle between the solution and the problem.
comment:1 Changed 5 years ago by flesler
Hi the7erm
We rejected a similar feature, although we had all ready to commit, because of a cite on a spec on webforms.
Check #2726. I'll close this soon, reply if you have something to add.
comment:2 Changed 5 years ago by ygirouard
I'm not sure if this works with server-side languages other than php, but if you pass key/value pairs where the key has a [something] appended to its name, php will convert it into an array where "something" becomes an index.
So, if you want to pass a multi-dimensional array when posting, you could do something like this:
Let's say you want to pass something like this:
var options = {
"a":"1",
"b":{"I":"1", "II":"2"},
}
So that you receive this on server-side (in php in my case):
array( "a"=>"1", "b"=>array( "I"=>"1", "II"=>"2" ) )
You could pass this in your post:
var options = {
"a":"1",
"b[I]":"1",
"b[II]":"2"
}
It may need a bit of manual parsing in javascript if you had a pre-constructed object you want to pass, but that's easy enough to do using the "for (key in object) {}" method...
i.e.
var options = {
"a":"1",
"b":{"I":"1", "II":"2"},
}
var b = options.b;
delete(options.b);
for (i in b) {
options["b[" + i + "]"] = b[i];
}
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

nightly build from 2008-05-15 with mda fix.