I am trying to pass array of names to spring controller using axios get request.if i try to pass single value in params it works fine but if pass array in params then i am getting error "CORS header ‘Access-Control-Allow-Origin’ missing". I tried this
this is url
http://localhost:8080/onlineshopping/view/category/products?name[]=Alex&name[]=john
taskAction.js
var request = {
params: {
name : JSON.parse(localStorage.getItem('name'))
}
}
const res = await axios.get(`http://localhost:8080/onlineshopping/view/category/products`,request);
dispatch({
type: GET_CATEGORY_PRODUCTS,
payload: res.data
});
};
but this is not working
My spring controller
@RequestMapping(value = "/view/category/products")
public Map<String, Object> viewProducts(
@RequestParam(value = "name[]", required = false) List<String> name,
HttpServletRequest request, HttpServletResponse response) {
Map<String, Object> mapproducts = new HashMap<String, Object>();
for (String Str : name) {
System.out.println("name " + Str);
}