1.前端获取验证码代码
//获取验证码
var intel = "";
var loading = true;
$("#getCode").on('click', function () {
if (loading) {
loading = false;
$("#telTip").text("");
$("#codeTip").text("");
var tel = $("#tel").val();
app.postAjax({
url: '/user/account/sendSMSCodeByTel',
data: {
tel: tel
},
success: function (result) {
if (result.statusCode == 100) {
app.alert(result.msg);
clearInterval(intel);
var sends = 120;
intel = setInterval(function () {
if (sends > 0) {
$("#getCode").attr("disabled", "true");
$("#getCode").text(sends + '秒');
sends--;
} else {
$("#getCode").text('获取验证码');
$("#getCode").removeAttr("disabled");
clearInterval(intel);
}
}, 1000);
loading = true;
} else {
$("#telTip").text(result.msg);
loading = true;
}
}
}, '正在获取验证码...')
}
});
2.确认验证码是否正确
app.postAjax({
url: '/enterpriseManage/userManage/confirmCode',
data: { phone: userManage_index.phone, code: userManage_index.code },
success: function (result) {
if (result.statusCode == 100) {
userManage_index.editPhone = userManage_index.phone;
app.alert(result.msg, function () {
clearInterval(userManage_index.intel);//确认后删除定时器(一般不用,有时候会用到)
});
} else {
app.error(result.msg);
}
}
});