ajax实例
jsp:
1. 引入jqery.js
2. 写function
function xx () {
if($("#formID").validationEngine('validate')){
var url = "<%=staticName%>/actions/login/user!resetBankCustomerManagerPassword.html";
var bool=true; // ajax外层art.dialog,不能引用ajax内部的return false时,定义一个变量
$.ajax({
cache: true,
dataType: "text",
type: "POST",
url: url,
data: $('#formID').serialize(),// 你的formid
async:false, // 表示同步,默认为true,为不同步,一般用默认
success:function(data) {
var dataTrim = $.trim(data);
if(dataTrim=="true"){
//$("#formID").validationEngine('hide');
}else if(dataTrim=="sjhwk"){
jQuery("#passwordErreTip").css("display","block");
jQuery("#passwordErreTip").html("手机号不能为空!");
//return false;
bool=false;
}else if(dataTrim=="yzmwk"){
jQuery("#passwordErreTip").css("display","block");
jQuery("#passwordErreTip").html("验证码不能为空!");
//return false;
bool=false;
}else if(dataTrim=="yzmcw"){
jQuery("#passwordErreTip").css("display","block");
jQuery("#passwordErreTip").html("验证码不正确!");
//return false;
bool=false;
}
},
error:function(data) {
alert("异常!");
bool=false;
}
});
return bool;
}else{
return false;
}
}
action:
/** 获取密码 */
public void resetBankCustomerManagerPassword() {
try {
// 校验验证码
String mobileno = pro.getMobileno();
String yzm = pro.getYzm();
String yzmSession = (String)request.getSession().getAttribute("checkCode");
String yzmStatus = "true";
if("".equals(mobileno) || null==mobileno){
yzmStatus = "sjhwk";
}
if("".equals(yzm) || null==yzm){
yzmStatus = "yzmwk";
}
if(!yzm.equalsIgnoreCase(yzmSession)){
yzmStatus = "yzmcw";
}
HttpServletResponse response=ServletActionContext.getResponse();
response.setContentType("text/html;charset=utf-8");
PrintWriter out = response.getWriter();
out.println(yzmStatus.trim());
out.flush();
out.close();
if("true".equals(yzmStatus)){
// 生成重置的帐户密码,修改数据库的密码
int randomPassword = (int) (Math.random()*(999999-100000)+100000);
String randomMD5Password = MD5Util.parseMD5(String.valueOf(randomPassword));
int result = userService.updateBankCustomerManagerPassword(randomMD5Password);
// 发送到手机
String custName = request.getParameter("custName");
}
} catch (Exception e) {
}
}
相关推荐
结束数据方法的参数,该如何定义?-- 集合为自定义实体类中的结合属性,有几个实体类,改变下标就行了。<input id="add" type="button" value="新增visitor&quo