I am facing a challenge with making an ajax GET request where I need to submit an array of checkboxes, all with the same name. The checkboxes are defined as follows:
type[] = new
type[] = used
type[] = refurbished
The purpose of this is to fulfill the requirements of an API I am trying to access. However, I am unsure of how to accomplish this task.
Everything else is functioning properly with the API except for these checkboxes.
The checkboxes are set up in the code snippet below:
self.types = ['new', 'used', 'refurbished'];
//....
<label ng-repeat="type in search.types">
<input
type="checkbox"
name="type[]"
value="{{type}}"
> {{type}}
</label>
Values for the API request are added as shown in the example below:
dataObj['price'] = $scope.formData.max_price;
//similar approach needed for the type[] checkboxes
These values are then sent to the API:
return $http({
url: APIUrl + "search/",
method: "GET",
params: dataObj
});
//etc
The parameters to be posted to the API need to follow this format:
price = 400000
type[] = new
type[] = refurbished
//Note: "used" was omitted as the corresponding checkbox was not checked
It is important to emphasize that this format is not flexible and is a requirement of the API.
Thank you!