I’m using JQuery to make a JSON request back to the server and it seems that it’s parameter serialization is hard-coded to what PHP expects instead of being generic in nature. Basically I have an object that looks like this:
{
foo: 1,
bar : [1, 3, 5]
}
And it serializes it to:
foo=1&bar[]=1&bar[]=3&bar[]=5
Is there anyway to make it just do?
foo=1&bar=1&bar=3&bar=5
It seems to me that jQuery shouldn’t be so tied to what a handful of server side frameworks expect as a naming convention. If I wanted my param to be called bar[] I could easily name it that myself if it’s what my server-side code expects.
I’m assuming you’re using JQuery 1.4. You should take a look at this: http://benalman.com/news/2009/12/jquery-14-param-demystified/
The author discusses why they made JQuery behave this way, and makes some excellent points. For example, if you don’t use the “square bracket syntax”, you can’t pass in arrays with only a single value.
He also offers a work-around:
This will tell JQuery to use the non-bracket method of serialization.