$httpParamSerializerJQLike doesn't encode array indices (as opposed to $.param) #12393
Description
Why does pressing Enter while in the title posts the issue?
Anyway, found an important encoding difference between $.param
and $httpParamSerializerJQLike
.
When encoding arrays, sometimes it's fine to leave the index out like that: a[]=1&a[]=2
, which comes out as a = [1, 2]
on the other side.
Sometimes this is not the case, mostly when you have array of objects: a[][x]=1&a[][y]=2
, which comes out as a = [{ x: 1, y: 2 }]
, which is sometimes true, but what if you meant a = [{ x: 1 }, { y: 2 }]
? In this case you need to encode the array index like so: a[0][x]=1&a[1][y]=2
. JQuery does that with $.param
, and Rails for example knows how to handle it.
If indices are not given, the server only appends a new object to the array when there are duplicate keys, like so: a[][x]=1&a[][y]=2&a[][x]=3
, which should come out as a = [{ x: 1, y: 2 }, { x: 3 }]
.