ajax传参springmvc接收不到

2016-12-21 19:24:03来源:CSDN作者:qq_24949727人点击

$.ajax({				type:"POST",				url:"code/captchaVerify",				contentType: "application/json; charset=utf-8",				data:{"kaptchaCode":kaptchaCode},				dataType: "json",				success:function(data){					console.log(JSON.stringify(data));					if(data.isOK=="OK"){						alert("验证码OK");					}else{						alert("验证码WRONG");					}				}			});

    @RequestMapping(value = "/captchaVerify",method=RequestMethod.POST)     @ResponseBody//不加上前台解析不了     public String captchaVerify(String kaptchaCode,HttpServletRequest request, HttpServletResponse response) throws Exception {      	Map<String,String> result=new HashMap<>();    	HttpSession session = request.getSession();      	String code = (String)session.getAttribute(Constants.KAPTCHA_SESSION_KEY);     	System.out.println("kaptchaCode:"+kaptchaCode+"  ;code:"+code);    	if(StringUtils.isNotBlank(kaptchaCode)&&kaptchaCode.equalsIgnoreCase(code)){    		return "{/"isOK/":/"OK/"}";      	}else{    		return "{/"isOK/":/"WRONG/"}";      	}    }  

这样后台接收不到 
data:{"kaptchaCode":kaptchaCode}
发现
contentType: "application/json; charset=utf-8",
是以json格式传数据,后台要加 @RequestBody String kaptchaCode...

而aptchaCode的内容是kaptchaCode=ssss

contentType: "application/json; charset=utf-8",
去掉

@RequestBody   也去掉

aptchaCode的内容是ssss


最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台