Bug Tracker

Opened 7 years ago

Closed 6 years ago

#6376 closed bug (invalid)

ajax() data parameter's array handling worked in 1.3.2 but not 1.4.2

Reported by: nnnnnn321 Owned by:
Priority: undecided Milestone: 1.4.2
Component: ajax Version: 1.4.2
Keywords: ajax data 1.4.2 Cc:
Blocked by: Blocking:


The ajax() method doco here: http://api.jquery.com/jQuery.ajax/ indicates that the "data" parameter handles arrays by creating multiple request params with the same key name, and gives an example: {foo:["bar1", "bar2"]} becomes '&foo=bar1&foo=bar2'.

That is exactly how I would expect multiple values for the same key to be submitted, and it did work like this in version 1.3.2. However, I recently upgraded to jQuery version 1.4.2 and now my ajax calls don't work. Debugging on the server side, I find that for the above example instead of creating multiple request params with the specified key name of "foo", jQuery is creating the request param as "foo[]" (with the square brackets part of the name). Not having time to clarify just what jQuery is doing, and certainly not having time to change all my existing code, I had to go back to jQuery 1.3.2 where the ajax calls work beautifully.

In searching to see if this has previously been reported I found a ticket or two from people who seemed to want square brackets on their parameter names, but I disagree that this is a good idea (surely if there is a good reason to want that on the server side you can just code it as "foo[]" in the client ajax call?) and in any case if this new behaviour is on purpose please update the doco to match.

Attachments (1)

jsend.html (1.1 KB) - added by T.J. Crowder 7 years ago.
Failing test case

Download all attachments as: .zip

Change History (4)

Changed 7 years ago by T.J. Crowder

Failing test case

comment:1 Changed 7 years ago by T.J. Crowder

I've attached a test case demonstrating the problem. When you click the Go button, the POST data sent is:


...e.g., the brackets are included in the field name, even though the field name does not have them ("c[]" rather than "c"). This is a very PHP-specific thing to do, should only be done with some kind of flag that you enable it with (or, of course, by having the object key actually include the "[]" in the object).

comment:2 Changed 7 years ago by elfuego

Even when you have a string with numbers, like f.e. node=123, it gets interpreted as an array leaving you with node=1&node=2&node=3.

comment:3 Changed 6 years ago by snover

  • Priority set to undecided
  • Resolution set to invalid
  • Status changed from new to closed

As per the jQuery.ajax documentation, set traditional to true to use the pre-1.4 method of serialization.

Note: See TracTickets for help on using tickets.