Bug Tracker

Ticket #6376 (closed bug: invalid)

Opened 4 years ago

Last modified 4 years ago

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:
Blocking: Blocked by:

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

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

Change History

Changed 4 years ago by T.J. Crowder

Failing test case

comment:1 Changed 4 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:

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

comment:2 Changed 4 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 4 years ago by snover

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

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.