ajax发送请求,后台接收不到的问题
发布时间:2020-12-16 03:28:52 所属栏目:百科 来源:网络整理
导读:前台代码: $.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,textS
前台代码:
$.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}, (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |