function setPayPwd(){
var mobile=document.getElementById("telPhone").value;
var payPassword=document.getElementById("payPwd").value;
var rePayPassword=document.getElementById("rePayPwd").value;
// alert("mobile="+mobile+"And"+"payPassword="+payPassword);
if(payPassword!=rePayPassword){
alert("前后輸入的密碼不一致,請重新設置!");
$("#payPwd").focus();
return;
}
alert("密碼一致,開始交互");
//前后台交互
$.ajax({
type: "POST", //用POST方式傳輸
dataType: "json", //數據格式:JSON
url: '${path}/member/setPayPwd.shtml', //目標地址
data: {mobile:mobile, payPassword: payPassword},
error: function (XMLHttpRequest, textStatus, errorThrown) { },
success: function (msg){
if(msg.ret !=1){
layer.msg(msg.msg);
}else{
layer.msg('驗證成功,請設置支付密碼!', {
time: 1000 //2秒關閉(如果不配置,默認是3秒)
}, function(){
window.location.href="${path}/goods/index.shtml";
});
}
}
});
//alert("設置成功!");
}
觸發此方法的語句;
<input type="button" onclick="setPayPwd()" value="提交" />
后台接收代碼:
@RequestMapping("/setPayPwd")
public String setPayPwd(ModelMap mm,String mobile,String payPwd){
JSONObject json = new JSONObject();
Map<String, Object> returnMap = new HashMap<String,Object>();
if(StringUtil.isBlank(mobile)||StringUtil.isBlank(payPwd)){
json = getJson(0, null, "參數缺失!");
}
Map<String,String> map = new HashMap<String,String>();
map.put("membermobile", mobile);
map.put("memberpaypwd", payPwd);
returnMap = shopMemberService.login(map);
if(returnMap!=null&&((String)returnMap.get("isResult")).equals("0")){
json.put("ret", 1); //0失敗 1成功
json.put("data", returnMap); //返回數據
json.put("msg", "設置成功!"); //返回消息
setUser(returnMap);
}else{
json = getJson(0, null, (String)returnMap.get("memberMsg"));
}
mm.put("json",json);
return AJAX_RETURN;
}
歡迎加入WEB前端互動交流群04,海量學習資料免費送