Skip to content

Instantly share code, notes, and snippets.

@htom78
Created April 16, 2016 08:52
Show Gist options
  • Save htom78/3c267c6eb55f0a253dfb8237e905ce4d to your computer and use it in GitHub Desktop.
Save htom78/3c267c6eb55f0a253dfb8237e905ce4d to your computer and use it in GitHub Desktop.

Revisions

  1. htom78 created this gist Apr 16, 2016.
    154 changes: 154 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,154 @@
    $("#smsLogin").submit(function(e)
    {
    var postData = $(this).serializeArray();
    var formURL = $(this).attr("action");
    $.ajax(
    {
    url: formURL,
    type: "POST",
    data: postData, // our data object
    dataType: 'json', // what type of data do we expect back from the server
    success: function (data, textStatus, jqXHR) {
    if (data.status == true) {
    //跳转到下个页面
    location.href = '/index.php?r=linkspread/activity';
    } else {
    //显示错误信息
    $('.errorSummary').remove();
    $('#smsLogin').prepend(data.error);
    }
    },
    error: function (xhr, type) {
    alert(xhr.response);
    }
    });
    e.preventDefault(); //STOP default action
    // e.unbind(); //unbind. to stop multiple form submit.
    });

    $("#submitLogin").on('click', function (e) {
    var mobile = $("#smsLogin input#SmsLogin_mobile").val();
    if (!mobile) {
    alert("请出入正确的手机号码");
    return false;
    }
    var code = $("#smsLogin input#SmsLogin_code").val();
    if (!code) {
    alert("请出入正确的验证码");
    return false;
    }
    $("#smsLogin").submit();
    });
    $('.js-get-code').on('click', function (e) {
    if ($(".js-get-code").hasClass('disabled')) {
    return false;
    }
    if ($(".js-get-code").hasClass('clicked')) {
    return false;
    }
    var mobileNo = $('#SmsLogin_mobile').val();
    if (!mobileNo) {
    alert('手机号不能为空');
    return false;
    }
    $(".js-get-code").addClass('clicked');
    $.ajax({
    method: "POST",
    url: '/index.php?r=linkspread/SendLoginSms',
    data: {'phone': mobileNo, 'url': window.location.href},
    dataType: 'json',
    success: function (data) {
    if (data.status == true) {
    $(".js-get-code").addClass('disabled');
    InterValObj = window.setInterval(SetRemainTime, 1000); //启动计时器,1秒执行一次
    } else {
    $(".errorSummary").show();
    $(".errorSummary ul").html("<li>" + data.message + "</li>");
    // alert(data.message);
    }
    return false;
    },
    error: function (XHR, e, r) {
    alert("发送失败:" + XHR.responseText);
    return false;
    },
    complete: function () {
    $(".js-get-code").removeClass('clicked');
    }
    });
    return false;
    });

    var InterValObj; //timer变量,控制时间
    var count = 5; //间隔函数,1秒执行
    var curCount = 60;//当前剩余秒数
    var code = ""; //验证码
    var codeLength = 4;//验证码长度

    //timer处理函数
    function SetRemainTime() {
    if (curCount == 0) {
    window.clearInterval(InterValObj);//停止计时器
    $(".js-get-code").removeClass("disabled");//启用按钮
    $(".js-get-code").val("重发验证码");
    code = ""; //清除验证码。如果不清除,过时间后,输入收到的验证码依然有效
    curCount = 60;
    }
    else {
    curCount--;
    $(".js-get-code").val("重发(" + curCount + ")");
    }
    }

    $(".voicecheck").on('click', function (e) {
    if ($(".js-get-code").hasClass('disabled')) {
    return false;
    }
    if ($(".js-get-code").hasClass('clicked')) {
    return false;
    }
    $(".js-get-code").addClass('clicked');
    var mobileNo = $('#SmsLogin_mobile').val().trim();
    if (!mobileNo) {
    alert('手机号不能为空');
    return;
    }
    $.ajax({
    method: "POST",
    url: '/index.php?r=linkspread/SendLoginVoiceSms',
    data: {'mobile': mobileNo, 'url': window.location.href},
    dataType: 'json',
    success: function (data) {
    if (data.status == true) {
    $(".js-get-code").addClass('disabled');
    InterValObj = window.setInterval(SetRemainTime, 1000); //启动计时器,1秒执行一次
    $('.voicecheckinfo').show();
    } else {
    $(".errorSummary").show();
    $(".errorSummary ul").html("<li>" + data.message + "</li>");
    //alert(data.message);
    }
    return false;
    },
    error: function (XHR, e, r) {
    alert("发送失败:" + XHR.responseText);
    return false;
    },
    complete: function () {
    $(".js-get-code").removeClass('clicked');
    }
    });
    return false;
    });
    $.ajax({
    type: "POST",
    url: '/index.php?r=linkspread/saveLog',
    data: {type: "get_in"},
    dataType: 'json',
    error: function (XHR, e, r) {
    return true;
    },
    complete: function () {
    return true;
    }
    });