-
Notifications
You must be signed in to change notification settings - Fork 27.4k
$httpParamSerializerJQLike doesn't encode array indices (as opposed to $.param) #12393
Comments
@odedniv could you please share more details? A reproduce scenario? |
Wow @pkozlowski-opensource, you were fast. EDIT: funny, I see as if I made the edit 5 minutes before you made the comment even though I saw your comment adding up while I was typing. |
Suggestion: why not have |
@odedniv There is no |
Right @Narretz, figured that might be the case. In any way, I still think the JQLike implementation should just be, JQ implementation. |
…objects Follow jQuery when serializing arrays that contain objects Close angular#12393
#12398 should take care of this |
landed as 18a2e4f |
…objects Follow jQuery when serializing arrays that contain objects Close angular#12393 Close angular#12398
…objects Follow jQuery when serializing arrays that contain objects Close angular#12393 Close angular#12398
I'm using Ionic an was able to update the Angular version so I threw this factory together with the fixed code. It's not pretty but it might be useful to someone.
|
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 asa = [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 asa = [{ x: 1, y: 2 }]
, which is sometimes true, but what if you meanta = [{ 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 asa = [{ x: 1, y: 2 }, { x: 3 }]
.The text was updated successfully, but these errors were encountered: