I'm trying to make an AJAX call using plain javascript to a Spring controller. The call fails with "Required String parameter 'allowedRoles' is not present"
The controller:
@RequestMapping(path = "/updateRoles", method = RequestMethod.POST)
public String updateRoles(@RequestParam("allowedRoles") String allowedRoles,
final Map<String, Object> model) {
return "services";
}
And the AJAX call:
var xhttp;
if (window.XMLHttpRequest) {
// code for modern browsers
xhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.open("POST", "/services/updateRoles", true);
xhttp.setRequestHeader("Content-type", "application/json");
xhttp.send({"allowedRoles":allowedRoles});
I have also tried
xhttp.send("allowedRoles=" + allowedRoles);
But the result is the same