Skip to main content

Bug Tracker

Side navigation

#6376 closed bug (invalid)

Opened March 29, 2010 11:17PM UTC

Closed October 31, 2010 08:55AM UTC

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:
Description

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 May 10, 2010 08:49AM UTC.

    Failing test case

Change History (3)

Changed May 10, 2010 08:52AM UTC by T.J. Crowder comment:1

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

a=1&b=testing+one+two+three&c%5B%5D=x&c%5B%5D=y&c%5B%5D=z

...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).

Changed June 25, 2010 10:13AM UTC by elfuego comment:2

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.

Changed October 31, 2010 08:55AM UTC by snover comment:3

priority: → undecided
resolution: → invalid
status: newclosed

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