-
Notifications
You must be signed in to change notification settings - Fork 27.4k
$http get array params are sent incorrectly #3121
Comments
I can confirm the issue. In AngularJS 1.0.6 the query string would have been: |
jQuery has managed HTTP beautifully since I can remember, perhaps we should take a peek into the test suite there before we discover any more surprises. Otherwise, I'm happy to make patch, just need to know what to do — @IgorMinar @mhevery @vojtajina ? |
@benschwarz - Hi Ben. Thanks for submitting this issue. There is no particular standard for how arrays should be serialized into query strings. Different back ends expect different formats. This current method (in 1.1.x) was chosen specifically because it allows the developer the most flexibility. See the PR for this: #2522 You can get your desired serialization by giving setting params to:
In the long term we are looking to make the serialization of URL queries pluggable so that you will be able to specify your own strategy. |
@petebacondarwin ok… I thought that arrays were actors[]=value, myself… but I didn't realise that there are other common implementations. Perhaps its worth adding to the docs how the params work for GET requests, and how one can achieve the desired result? |
@benschwarz - the latest version of the docs is a bit more clear. |
@petebacondarwin sounds like there is nothing to fix here. Thanks for the input. |
So the common workaround of appending"[]" to the array-type variable name doesn't work. I am using Angular 1.5.7, and when I give the following parameters:
I get the following url:
It is so close to right - but Angular serializes the |
This is a 3-year old issue, so things have evolved since then 😄 |
@petebacondarwin thx, this resolved my problem, cheers |
what if I have to send array of objects? |
@yasir-rafiq - query params must be string based. If you want to send an array of objects then you will need to serialize the objects to strings first. |
thnks @petebacondarwin |
If I make a request with:
The query string should be:
?actors[]=Elvis&actors[]=Jane&actors[]=Frances
Instead, its being set as:
?actors=Elvis&actors=Jane&actors=Frances
Turns out: Hashes aren't sent correctly either #2091
The text was updated successfully, but these errors were encountered: