0
我試圖使用普通的JavaScript到Spring控制器的AJAX調用。 調用失敗, 「需要字符串參數 'allowedRoles' 不存在」春天 - POST參數與香草javascript
控制器:
@RequestMapping(path = "/updateRoles", method = RequestMethod.POST)
public String updateRoles(@RequestParam("allowedRoles") String allowedRoles,
final Map<String, Object> model) {
return "services";
}
而AJAX調用:
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});
我也曾嘗試
xhttp.send("allowedRoles=" + allowedRoles);
但結果是一樣的
你是不是送你發送參數請求主體。 –
@ M.Deinum我該如何發送參數? – algiogia