前台代码:
$.ajax({
type : 'POST',url : '<%=basePath %>user/getorgRoles.do',data : {'orgId' : orgId},async: false,contentType: "application/json; charset=utf-8",dataType : 'json',success : function(data){
},error : function(XMLHttpRequest,textStatus,errorThrown) {
}
});
后台代码:
@ResponseBody
@RequestMapping("/getorgRoles")
public Object getorgRoles(@RequestParam(value = "orgId",required = true) String orgId) {
List<Tempuser> tempuserList = null;
JSONObject jsonObjectFromMap = null;
try
{
tempuserList = tempuserService.getorgRole(Long.parseLong(orgId));
jsonObjectFromMap = JSONObject.fromObject(tempuserList);
}
catch (Exception e)
{
e.printstacktrace();
}
return jsonObjectFromMap;
}
问题出在:@RequestParam 不能接收 contentType : "application/json; charset=utf-8" 的请求。
如果后台必须要用@RequestParam,
前台2个地方必须改:
1、contentType 改为"application/x-www-form-urlencoded"
2、data: 改为{'orgId':orgId},