i have some html snip like this
<input type="checkbox" name="color" value="red"/>red
<input type="checkbox" name="color" value="green"/>green
<input type="checkbox" name="color" value="purple"/>purple
<input type="checkbox" name="color" value="grey"/>grey
and i want to use jquery to post value to server, so i used jquery like this
$.post('/test', {'color': ['red', 'green']});
i did search this question in stackoverflow, but people say it’s should be ‘color[]’ instead of ‘color’, but whenever i used ‘color’ or ‘color[]’ firebug displayed the post data is ‘color%5B%5D=red&color%5B%5D=green’, and my server can’t work right, but when using
<input type="submit" value="submit"/>
to post firebug says the data is ‘color=red&color=green’, and my server work right.
How could it be? my jquery version is 1.4.4
For some reason, the jQuery developers decided that PHP’s bizarre handling of multiple controls with the same name is The Correct Way. As a consequence, when submitting an array of data, jQuery will append
[]to the name (%5B%5Dis just a URL encoded representation of[]).That suggests that you are using something other than PHP to process the data so PHP’s magic handling of
[]in names does not apply.You can either look for
color[]on the server…e.g.
… or you can set traditional mode to stop jQuery PHPifying your data.
Then normal access should work: