When passing an object as the data to the ajax call, I am getting some unexpected results. For some reason, jQuery is adding square brackets to my parameter names if their value is an array. For instance...
var obj =
{
name: "John Doe",
courses: [ 1, 2, 4 ]
};
...becomes name=John+Doe&courses[]=1&courses[]=2&courses[]=4 instead of name=John+Doe&courses=1&courses=2&courses=4.
Why is jQuery adding the square brackets?
Here is a working example: http://jsfiddle.net/BrHSy/
Update:
I expect the above example to produce a string similar to the query string in this example:
<html>
<head></head>
<body>
<form method="GET">
<input type="hidden" name="name" value="John Doe"/>
<input type="hidden" name="courses" value="1"/>
<input type="hidden" name="courses" value="2"/>
<input type="hidden" name="courses" value="4"/>
<button>Go!</button>
</form>
</body>
</html>
Notice that the query string which is produced by the form (www-form-urlencoded) does not have the square brackets.