Side navigation
#13611 closed bug (duplicate)
Opened March 14, 2013 09:27PM UTC
Closed March 15, 2013 02:31PM UTC
Last modified March 15, 2013 04:19PM UTC
$.param should treat empty arrays/objets like empty strings
Reported by: | daniellibanori@gmail.com | Owned by: | daniellibanori@gmail.com |
---|---|---|---|
Priority: | low | Milestone: | None |
Component: | ajax | Version: | 1.9.1 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
It can't send empty array via Ajax:
$.post('/foo', { empty: [] });
Related: http://bugs.jquery.com/ticket/6481
Attachments (0)
Change History (8)
Changed March 15, 2013 12:23AM UTC by comment:1
component: | unfiled → ajax |
---|---|
owner: | → daniellibanori@gmail.com |
priority: | undecided → low |
status: | new → pending |
Changed March 15, 2013 02:04PM UTC by comment:2
The main question here is: how to send an empty array to server?
Actually, this issue is related with $.param.
Changed March 15, 2013 02:31PM UTC by comment:3
resolution: | → duplicate |
---|---|
status: | pending → closed |
Duplicate of #6481.You're right, that is the question. How would you send an empty array using a form post without JavaScript? You wouldn't. The application/x-www-form-urlencoded MIME type doesn't support it. There is no governing standard or de-facto convention for how to send an array via a form.
The client and server can create any convention they'd like regarding what **string** might represent an empty array, but that's not something jQuery can help you with. We only handle the client end.
To send complex JavaScript-like data structures that don't resemble user form data entries, use JSON.
Changed March 15, 2013 02:56PM UTC by comment:4
So you should remove $.param ability to send non-empty arrays.
Why can you send not empty array but you can't send empty array. This seems arbitrary.
Changed March 15, 2013 03:29PM UTC by comment:5
It *is* arbitrary to some extent since there is no standard. We tried it both ways and this was the best compromise that broke the fewest things. Deal with it on your server, or convert the empty array to a string if you have no control over the server. You could also start lobbying to create a standard here, but I would guess that nobody would care enough to do anything about it since there are better solutions like JSON. Just don't blame jQuery, we can't read minds.
Changed March 15, 2013 03:51PM UTC by comment:6
I do know you can't read minds, so I wrote a bug report instead of just blaming jQuery. :)
I do think people care about it, as I am not the first one complaining about empty array serialization.
jQuery already serializes arrays, just not the empty ones. The current array serialization format supports an empty array, jQuery just doesn't serialize it. Why?
Changed March 15, 2013 03:59PM UTC by comment:7
Go back and read the old ticket. Summarize here.
Changed March 15, 2013 04:19PM UTC by comment:8
_comment0: | I got it. The main problem is { a: [''] } would look like { a: [] }. \ \ Thank for your attention. → 1363365026888596 |
---|
I got it. The main problem is { a: [''] }
would look like { a: [] }
.
Thank for your attention.
From the discussion in the ticket you've linked, it sounds like it shouldn't. I think we'd be happy to hear your argument though.