Bug Tracker

Opened 11 years ago

Closed 11 years ago

Last modified 8 years ago

#4177 closed bug (worksforme)

jQuery.param() handles arrays very strangely

Reported by: wmleler Owned by:
Priority: minor Milestone: 1.3.2
Component: core Version: 1.3.1
Keywords: param array Cc:
Blocked by: Blocking:

Description

If you create an object containing an array, and pass it to jQuery.param(), it creates two name/value pairs with the same name, which is not valid HTTP.

For example, $.param({ a: [5, 12], b: 'hello' }) creates a=5&a=12&b=hello

If I use this as a query string into PHP, it only sees a=12 (the 5 is lost).

Attachments (1)

bug2.html (605 bytes) - added by wmleler 11 years ago.
small program to reproduce the bug

Download all attachments as: .zip

Change History (2)

Changed 11 years ago by wmleler

Attachment: bug2.html added

small program to reproduce the bug

comment:1 Changed 11 years ago by dmethvin

Resolution: worksforme
Status: newclosed

I'm not sure what you mean by "not valid HTTP" since isn't related to the HTTP protocol. Try this sample code:

<form method="get" action="http://google.com">
<input type="checkbox" name="checker" value="1">
<input type="checkbox" name="checker" value="2">
<input type="checkbox" name="checker" value="3">
<input type="submit" value="submit">
</form>

It will submit a GET request like this:

http://www.google.com/?checker=1&checker=2&checker=3

That would be equivalent to passing checker: [1,2,3] to jQuery.param.

PHP handles multivalued forms in a nonstandard way, so that may be what is causing confusion:

http://www.spsu.edu/cs/faculty/bbrown/papers/php2.html

Note: See TracTickets for help on using tickets.