登陆和手机验证吗的ajax

$(function () {
$(".loading").addClass("loader-chanage")
$(".loading").fadeOut(500);

window.mui = require('lib/mui.min');

$.ajaxSetup({
    type: "POST",
    dataType: 'json',
    beforeSend: function (xhr, options) {
        if (options.url.indexOf(window.baseUrl) == -1) {
            options.url = window.baseUrl + options.url;
        }
    },
    data: {

    },
    error: function (data) {
        mui.toast('网络异常', { duration: 'short', type: 'div' })
    }
});


/* 获取验证码+60秒 */
var InterValObj; //timer变量,控制时间
var count = 60; //间隔函数,1秒执行
var curCount;//当前剩余秒数
function sms() {
    curCount = count;
    //设置button效果,开始计时
    $("#verify_1").attr("disabled", "true");
    $("#verify_1").html(curCount + "s");
    InterValObj = window.setInterval(SetRemainTime, 1000); //启动计时器,1秒执行一次
    $(".verify_1").css("background", "#B0B0AF !important")
};
function SetRemainTime() {
    if (curCount == 0) {
        window.clearInterval(InterValObj);//停止计时器
        $("#verify_1").removeAttr("disabled");//启用按钮
        $("#verify_1").val("重新发送");
    }
    else {
        curCount--;
        $("#verify_1").val(curCount + "s");
        $(".verify_1").css("background", "#B0B0AF !important")

    };
};
$("#login").click(function () {
    var phone = $("#account").val();
    var pwds = $("#pwd").val();
    $.ajax({
        url: '/index/login',
        data: { password: pwds, phone: phone },
        success: function (data) {
            if (data.code) {
                mui.toast(data.code + ':' + data.description, { duration: 'short', type: 'div' })
                return;
            }
            window.location.href = 'index.html';

        },
        error: function (e) {
            console.log(e);
        }
    });
    return false;

});

$('#verify_1').click(function () {
    var phone = $("#account").val(),
        $this = $(this);
    if (!phone) {
        mui.toast('请输入手机号码', { duration: 'short', type: 'div' })
        return;
    }
    mui.toast('验证码已发送', { duration: 'short', type: 'div' });
    if ($this.prop('disabled')) {
        mui.toast('请稍后重试', { duration: 'short', type: 'div' });
        return;
    }
    if( $this.data('disabled')) return;
    $this.data('disabled', true);
    var num = 60;
    $this.text('60s');
    var timer = setInterval(function () {
        num -- ;
        $this.text(num+'s');
        if(num == 0){
            clearInterval(timer);
            $this.text('重新获取验证码');
            $this.data('disabled', false);
        }
    },1000);
    $.ajax({
        url: '/index/phoneVerify',
        data: { phone: phone },
        success: function (data) {
            if (data.code) {
                mui.toast(data.code + ':' + data.description, { duration: 'short', type: 'div' })
                return;
            }
            //$("#codes").val(data);
        },
        error: function (e) {
            console.log(e);
        }
    }).always(function () {
        $this.data('disabled', false)
    });

});


$("#login1").click(function () {
    var phone = $("#account").val();
    var password = $("#password").val();
    if (!phone) {
        mui.toast('请输入手机号码', { duration: 'short', type: 'div' })
        return;
    }

    if (!password) {
        mui.toast('请输入验证码', { duration: 'short', type: 'div' })
        return;
    }
    $.ajax({
        url: '/index/phoneVerifyCode',
        data: { verifyCode: password, phone: phone },
        success: function (data) {
            if (data.code) {
                mui.toast(data.code + ':' + data.description, { duration: 'short', type: 'div' })
                return;
            }
            window.location.href = 'index.html';

        },
        error: function (e) {
            console.log(e);
        }
    });
    return false;

});

});

你可能感兴趣的:(登陆和手机验证吗的ajax)