[jQuery] jQuery 1.2 - Serialize a form as JSON
Hello,
I'm trying to serialize a form with select-fields defined as multiple,
e.g.:
~~~~~~~~~~~~~
<select multiple="multiple" name="test[]">
<option value="one" selected="selected">One</option>
<option value="two">Two</option>
<option value="three" selected="selected">Three</option>
</select>
~~~~~~~~~~~~~
When I now try this:
~~~~~~~~~~~~~
$("select").serialize();
~~~~~~~~~~~~~
or this:
~~~~~~~~~~~~~
$("select").serializeArray();
~~~~~~~~~~~~~
I get an empty string resp. array.
But I should get this:
~~~~~~~~~~~~~
test[]=one&test[]=three
~~~~~~~~~~~~~
resp. this:
~~~~~~~~~~~~~
{
test: ["one", "two"]
}
~~~~~~~~~~~~~
Whats wrong with my code?
PS: I'm currently using Prototype with PHP in the backend, there it
just works fine.