发送短信验证码

发送短信验证码

        //发送短信
        $("#btnSendcode").click(function () {
          var  $this = $(this);
            //检查是否输入手机号码
            if ($("#txtMobile").val() == "") {
                $.dialog.alert("对不起,请先输入手机号码!", function () {
                    $("#txtMobile").focus();
                });
                return false;
            }
            //设置按钮状态
            $("#txtCode").prop("disabled", false);
            $("#btnSendcode").prop("disabled", true);
            $.ajax({
                type: "POST",
                url: $("#btnSendcode").attr("url"),
                dataType: "json",
                data: { "mobile": $("#txtMobile").val() },
                timeout: 20000,
                success: function (data, textStatus) {
                    if (data.status == 1) {
                        $.dialog.tips(data.info, 2, "32X32/succ.png", function () {

                            var wait = 60;
                            time($this);
                            function time(o) {
                                if (wait == 0) {
                                    o.removeAttr("disabled").val('获取短信验证码')//.parents('.ui-button').addClass('ui-button-lorange').removeClass('ui-button-ldisable');
                                    wait = 60;
                                } else {
                                    //$('.J_userName').attr('readonly', 'readonly')
                                    o.attr("disabled", true).val(wait + '秒后可再次获取')//.parents('.ui-button').removeClass('ui-button-lorange').addClass('ui-button-ldisable');
                                    wait--;
                                    setTimeout(function () { time(o) }, 1000);
                                }
                                return false;
                            }

                        });
                    } else {
                        $("#btnSendcode").prop("disabled", false);
                        $.dialog.alert(data.info);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $("#btnSendcode").prop("disabled", false);
                    $.dialog.alert("状态:" + textStatus + ";出错提示:" + errorThrown);
                }
            });
        });

 

posted @ 2017-02-28 18:04  吖然-jronny  阅读(395)  评论(0编辑  收藏  举报