Skip to main content

Bug Tracker

Side navigation

#13975 closed bug (notabug)

Opened May 31, 2013 11:11PM UTC

Closed June 01, 2013 01:44AM UTC

Last modified June 06, 2013 01:12AM UTC

jQuery Changes Key Names in AJAX Calls (With no Documentation, For no Apparent Reason)

Reported by: anonymous Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.10.1
Keywords: Cc:
Blocked by: Blocking:

If you make a POST with $.ajax, and you don't stringify your data in advance, jQuery will change the names of any keys that have array values from "thatName" to "thatName[]". This behavior seems particularly strange to me, because jQuery normally takes great pains NOT to be opinionated (unless there is a standard involved, and there is no standard that I'm aware of which requires [] key names for AJAX calls).

Now, I understand that $.ajax is pretty integral to the library, and the jQuery community is used to the current behavior, so this bug likely can't be fixed entirely. However, I do see two partial solutions:

1) Add another option to ajax to allow disabling of this behavior. Currently there is a "traditional" option, but using that option also disables serialization of nested objects. Since there is currently no way to tell jQuery "please do everything as you normally would EXCEPT don't modify my keys", an option that allows that would be really handy.

2) Add more documentation highlighting this "feature" to the $.ajax documentation page. Currently the text "[]" doesn't even appear on that documentation page, but if a message to the effect of:

"jQuery is strongly opinionated when it comes to posting arrays, and it will modify your key names from "originalName" to "originalName[]" unless you use the traditional option or the new ____ option (created in 1) above)."

If either one of those were implemented it would likely save people (like myself) a lot of time and confusion (and both would be even better).

Attachments (0)
Change History (3)

Changed June 01, 2013 01:44AM UTC by dmethvin comment:1

resolution: → notabug
status: newclosed

You can file a suggestion for updating the documentation at . One to the effect of "the people who decided this are morons" won't be accepted, so think in terms of what useful information you would have wanted to solve your issue.

Changed June 05, 2013 10:53PM UTC by anonymous comment:2

Just out of curiosity, which part specifically was "not a bug"? The lack of an option to avoid the "[]", the lack of documentation explaining the situation, or both?

Changed June 06, 2013 01:12AM UTC by dmethvin comment:3

We're not interested in adding a third option for serializing form data, I agree it's confusing enough with two but there is no bug to be fixed in the code. Really, the best way to send data in a modern web page is JSON. If you think the current behavior can be explained better please provide a suggestion at the link above.