Bug Tracker

Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#13975 closed bug (notabug)

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

Change History (3)

comment:1 Changed 10 years ago by dmethvin

Resolution: notabug
Status: newclosed

You can file a suggestion for updating the documentation at https://github.com/jquery/api.jquery.com/issues?state=open . 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.

comment:2 Changed 10 years ago by anonymous

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?

comment:3 Changed 10 years ago by dmethvin

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.

Note: See TracTickets for help on using tickets.