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);
}
}
});