All
What I want to do is Adding multiple parameters with same name to request URL with AngularJS $http, making the URL sent like http://localhost:8080/?value=1&value=2.....
This post also described the similar situation:
Sending HTTP request with multiple parameters having same name
Could any one help with in AngularJS $http?
Thanks
You need to use an array like this:
var params = {};
params.someParmName = ['value1', 'value2'];
This will send value1 and value2 with the same querystring key 'someParmName'.
Here is an example GET request:
var parameters = {};
parameters.someParmName = ['value1', 'value2'];
$http({
url: 'api_url',
method: "GET",
params: parameters
});
You call also use URLSearchParams for the parameters. For example:
let params = new URLSearchParams();
params.append('someParmName', 'value1');
params.append('someParmName', 'value2');
// the following statement will form this url: ?someParmName=value1&someParmName=value2
http.get(api_url, {search: params});
Or
let params = new URLSearchParams();
params.set('someParmName', ['value1', 'value2'];);
// the following statement will form this url: ?someParmName=value1,value2
http.get(api_url, {search: params});