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
Passing multiple parameters to Http get requestBy using HttpParams. append() we can pass multiple parameters to HttpClient. get() method. We have to pass page & per_page parameters to the list of users API.
Query parameters are passed after the URL string by appending a question mark followed by the parameter name , then equal to (“=”) sign and then the parameter value. Multiple parameters are separated by “&” symbol.
Any word after the question mark (?) in a URL is considered to be a parameter which can hold values. The value for the corresponding parameter is given after the symbol "equals" (=). Multiple parameters can be passed through the URL by separating them with multiple "&".
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});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With