请求 ajax 基础配置

来源:互联网 发布:mac如何查看后台程序 编辑:程序博客网 时间:2024/06/06 19:39
$(".get").click(function () {    var phone_num = $("#phone_num").val();    if (phone_num.length != 11 || phone_num == null) {        alert("手机号输入错误");    } else {        $("input:button").attr("disabled", true);        var count_down = parseInt(60);        $(".get").val("60s重新发送");        $(".get").css("color", "#999");        $(".get").css("border-color", "#DEDEDE");        var time = setInterval(function () {            count_down--;            $(".get").val(count_down + "s重新发送");            if (count_down < 0) {                clearInterval(time);                $(".get").val("重新发送");                $(".get").css("color", "#17b4eb");                $(".get").css("border-color", "#17b4eb");                $("input:button").attr("disabled", false);            }        }, 1000);  登录页面  验证码 一分钟倒计时。
  var jsonObject = getJsonObject();//获取数据   由于从native端进行二次加密 写在公共方法里面            //请求参数追加自定义参数            jsonObject["method"] = "接口地址";  服务端要求数据格式 进行拼接            jsonObject["sendType"] = "0";            jsonObject["queryEacctFlag"] = "0";            jsonObject["mobile"] = phone_num;            $.ajax({                type: "POST",        //ajax 数据请求  格式几乎没变化                url: address,                data: jsonObject,                dataType: "json",                contentType: "application/x-www-form-urlencoded;charset=utf-8",                success: function (data) {                    if (null != jsonObject.timeStamp) {   //时间戳 签名                        if (data != null) {                            var retSign = window.android.desDecodeForHtml5(data.retSign);//调用native方法加解密。                            if (jsonObject.timeStamp == retSign) {                                if (data.retCode == "000000") {                                    if (isBeta) {                                        $("#test").val(data.dymcode);  验证码返回值自动填写                                    }                                    alert(data.retMsg);                                } else {                                    alert(data.retMsg)                                }                            } else {                                alert("校验签名失败1");                            }                        }                    } else {                        alert("校验签名失败2");                    }                },                error: function () {                    requestFailTips();                }            });        }    });    //点击登录    $("footer a").click(function () {        var val_get = $("#test").val();        var val = $("#phone_num").val();        if (val_get == null) {            alert("请输入验证码");        } else {            var jsonObject = getJsonObject();            //请求参数追加自定义参数            jsonObject["method"] = "借口";            jsonObject["dymCode"] = val_get;            jsonObject["isRegFlag"] = "1";            jsonObject["mobile"] = val;            $.ajax({                type: "POST",                url: address,                data: jsonObject,                dataType: "json",                contentType: "application/x-www-form-urlencoded;charset=utf-8",                success: function (data) {                    if (data.retCode == "000000") {                        if (data.isMember == "1") {                                                       setIsDefPwd(data.isDefaultMiMa);//公共方法的公共参数                            setMid(data.userId);                            setSessionId(data.sessionId);                            setEAcct(data.eacct);                            setEAcctName(data.userName);                            setMobile(data.mobile);                            if (getIsDefPwd() == "1") {                                if (getEAcct() == null || getEAcct() == "") {                                                                      window.location.href = "下一个页面html";                                } else {                                                                      alert("跳往设置登录密码页面");                                }                            } else {                                                              window.location.href = "login2.html";                            }                        } else {                                                                                  memberRegiter(val);                        }                    } else {                        alert(data.retMsg);                    }                },                error: function () {                    requestFailTips();                }            });        }    });});/** * 会员注册 */function memberRegiter(phone_num) {    alert("跳往登录页面");    var jsonObject = getJsonObject();    //请求参数追加自定义参数    jsonObject["method"] = "";    jsonObject["openType"] = "app";    jsonObject["mobile"] = phone_num;    $.ajax({        type: "POST",        url: address,        data: jsonObject,        dataType: "json",        contentType: "application/x-www-form-urlencoded;charset=utf-8",        success: function (data) {            if (data.retCode == "000000") {                setIsDefPwd(1);                setMobile(phone_num);                                window.location.href = ".html";            } else {                alert(data.retMsg);            }        },        error: function () {            requestFailTips();        },    });}

0 0
原创粉丝点击