java 部分:
@ResponseBody // spring 的注解,表示返回json 数据
public String resetPasswordResetCheckCode(HttpServletRequest request, HttpServletResponse response, String regphone) throws Exception{
SiteUser su = siteUserService.getSiteUserByMobile(regphone);
if(su!=null){
String code = null; // smsUtil.sendCheckCode(regphone);
WebUtils.putSession(request, response, "checkCode", code);
WebUtils.putSession(request, response, "checkCodeTime", new Date());
return code;
}else{
//手机号码没有注册
return "false";
}
}
前端部分:
function onCheckCode(){
var regphone =$("#regphone").val();
$('span.regsend').html("获取验证码");
$.ajax({
url: '${rc.contextPath}/user/resetPasswordResetCheckCode.do',
data : {regphone:regphone},
type : "post",
dataType : 'json',
success : function(data) {
// 后端 java 部分 return null , 前端ajax 不会 走到 success标签里面
if(data==false){
$("#regphone").next().html("该手机号未注册");
$('span.regsend').css("background","none");
}else{
sends.send();
$('span.regsend').css("background","#e8471a");
}
},
error : function(){
// 后端 java 部分 return null , 前端ajax直接走 error 标签
$("#regphone").next().html("验证码发送失败!请联系管理员,代码出错!");
}
});
}