wangzhiquan_ 2016-12-28 07:15 采纳率: 100%
浏览 2498
已采纳

js ajax POST 请求 刚进入js

POST http://localhost:8080/QiangkaBindServlet 404 (Not Found)

图片说明
send @ jquery.min.js:2
ajax @ jquery.min.js:2
code_btn_et1 @ main.js:80
dispatch @ jquery.min.js:2
u @ jquery.min.js:2

  • 写回答

2条回答 默认 最新

  • wangzhiquan_ 2016-12-28 10:08
    关注

    $(function(){
    //ajax判断是否已经注册
    //获取验证码按钮
    var isAppoint=false;
    console.log(openId);
    var submitData = {
    "openId" : openId,
    // "phone" : tel2,
    "type" : 1
    };
    /*$.ajax({
    type : "post",
    async : false,
    url : "/QiangkaBindServlet",
    dataType : "json",
    data : submitData,

        success : function(data) {
            if(Number(data.code)== 0 ){
                isAppoint=data.isAppoint;
                if(isAppoint==true){
                    $("#index1").hide();
                    $("#index2").show();
                    window.location.href="zz001.html";
                    //alert("您已经绑定过了");
                }
             }else{
             }
        },
        error : function(r) {
            //alert("判断用户是否绑定接口失败,当前网络繁忙!");
        }
    });*///end ajax 
    
    $("#get_code").bind("click", code_btn_et1 = function() {
    

    // alert("isAppoint="+isAppoint);
    if(isAppoint==true){
    alert("您已经绑定过了");
    return;
    }
    tel2 = $("#tel2").val();
    if (tel2 == '') {
    alert("请输入您要绑定的手机号");
    return;
    }

        var mobileNo=/^175[0-9]{8}$/ ;
        var mobileNo1=/^1(3[0-9]|5[0-35-9]|8[025-9]|47|7[5])[0-9]{8}$/ ;
        var mobileNo2=/^1760000[0-9]{4}$/;
        var cm=/^1(78[0-9]|47[0-9]|34[0-8]|(3[5-9]|5[017-9]|8[278])[0-9])[0-9]{7}$/ ;
        var cu=/^1(3[0-2]|5[256]|8[56]|76)[0-9]{8}$/;
        var ct=/^1((33|53|8[09]|77)[0-9]|349)[0-9]{7}$/
    
        var mn = new RegExp(mobileNo);
        var mn1 = new RegExp(mobileNo1);
        var mn2 = new RegExp(mobileNo2);
        var m = new RegExp(cm);
        var u = new RegExp(cu);
        var t = new RegExp(ct);
    
        if (!mn.test(tel2)&&!mn2.test(tel2)&&!mn1.test(tel2)) {
            alert("请输入正确手机号码!");
            return;
        }
    

    /* else if (m.test(tel2)) { //移动号码
    alert("请输入中国联通手机号码!");
    return;
    } else if (t.test(tel2)) { //电信号码
    alert("请输入中国联通手机号码!");
    return;
    } else if (!u.test(tel2)) { //非联通号码
    alert("您输入的手机号码无效,请重新输入!");
    return;
    }*/

        $("#get_code").unbind("click", code_btn_et1);
        seconds = 60;
    
        var submitData = {
            "openId" : openId,
            "phone" : tel2,
            "type" : 4
        };
        $.ajax({
            type : "post",
            async : false,
            url : "/QiangkaBindServlet",
            dataType : "json",
            data : submitData,
    
            success : function(data) {
                if(Number(data.code)== 0 ){
                    /*if(data.isAppoint==true){
                        //alert("该用户已经预约,无需再次预约");
                        $("#box4").show();
                        $("#goto1").one("click",function(){
                            window.location.href="index.jsp?type=3&openId="+openId;
                        });
                    }else 
                    if(data.isSichuan==false){
                        //alert("该用户不是四川用户,不能参加本活动");
                        $("#box6").show();
                        $("#get_code").bind("click", code_btn_et1);
                    }else if(data.isUsim==false){
                        //alert("该用户是Usim卡,不用换卡");
                        $("#box6").show();
                        $("#get_code").bind("click", code_btn_et1);
                    }else*/if(data.isAppoint){//需要换卡但是已经预约过了 
                        //alert("您已经预约过了,不用再预约了");
                        //$("#box4").show();
                        //window.location.href="index.jsp?type=3&openId="+openId;
                        //window.location.href="index.jsp?type=3&openId="+openId;
                        alert("您已经绑定过了");
                    }else if(data.success==true){
                        //alert("该用户不是Usim卡,短信发送成功");
                        timeCountDown();
                    }
                 }else{
                    alert("你输入的手机号码不合法");
                 }
            },
            error : function(r) {
                alert("抱歉,当前系统繁忙,请您稍后再试!");
                seconds = 0;
            }
        });//end ajax
    
    });//end click
    
    //--注册--提交
    $("#phone7").bind("click", bind_btn_et2 = function() {
        if(isAppoint==true){
            alert("您已经绑定过了");
            return;
        }       
        tel2 = $("#tel2").val();
        if (tel2 == '') {
            alert("请输入您要绑定的手机号");
            return;
        }
        var mobileNo=/^175[0-9]{8}$/ ;
        var mobileNo1=/^1(3[0-9]|5[0-35-9]|8[025-9]|47|7[5])[0-9]{8}$/ ;
        var mobileNo2=/^1760000[0-9]{4}$/;
        var cm=/^1(78[0-9]|47[0-9]|34[0-8]|(3[5-9]|5[017-9]|8[278])[0-9])[0-9]{7}$/ ;
        var cu=/^1(3[0-2]|5[256]|8[56]|76)[0-9]{8}$/ ;
        var ct=/^1((33|53|8[09]|77)[0-9]|349)[0-9]{7}$/
    
        var mn = new RegExp(mobileNo);
        var mn1 = new RegExp(mobileNo1);
        var mn2 = new RegExp(mobileNo2);
        var m = new RegExp(cm);
        var u = new RegExp(cu);
        var t = new RegExp(ct);
    
        if (!mn.test(tel2)&&!mn2.test(tel2)&&!mn1.test(tel2)) {
            alert("请输入正确手机号码!");
            return;
        }
    

    /* else if (m.test(tel2)) { //移动号码
    alert("请输入中国联通手机号码!");
    return;
    } else if (t.test(tel2)) { //电信号码
    alert("请输入中国联通手机号码!");
    return;
    } else if (!u.test(tel2)) { //非联通号码
    alert("您输入的手机号码无效,请重新输入!");
    return;
    }*/
    var yzm = $("#yzm").val();
    if (yzm == '') {
    alert("验证码不能为空!");
    return;
    }else if(yzm.length!=6){
    alert("验证码错误!");
    return;
    }
    /* if(!confirm("您确定要开通“1元省内网内随意打”业务吗?")){
    return;
    } /
    $("#phone7").unbind("click", bind_btn_et2);
    var submitData = {
    "openId" : openId,
    "phone" : tel2,
    "yzm" : yzm,
    "type" : 5
    };
    $.ajax({
    type : "post",
    async : true,
    url : "/QiangkaBindServlet",
    dataType : "json",
    data : submitData,
    success : function(data) {
    if(Number(data.code)== 0 ){
    if(data.isAppoint==true){
    alert("您已经绑定过了");
    // $("#box4").show();
    // $("#goto1").one("click",function(){
    // window.location.href="index.jsp?type=3&openId="+openId;
    // });
    }else if(data.rightYzm==false){
    alert("验证码错误");
    }
    /
    else if(data.isSichuan==false){
    $("#box6").show();
    //alert("该用户不是四川用户,不能参加本活动");
    }else if(data.isUsim==false){
    //alert("该用户是Usim卡,不用换卡");
    $("#box6").show();
    }else if(data.success==false){
    //alert("该用户不是Usim卡,但验证码错误");
    $("#box7").show();
    }*/
    else if(data.success==true){
    //alert("该用户不是Usim卡,预约成功");
    //alert("绑定成功");
    /*$("#index1").hide();
    $("#index2").show();
    $("#yzm").attr("readonly","true");
    $("#tel2").attr("readonly","true");
    $("#get_code").hide();*/
    window.location.href="zz001.html";

                    //  isAppoint=true;
                    //  window.location.href="http://www.baidu.com";
                    }
                 }else{
                    alert("你输入的手机号码不合法");
                 }
                $("#phone7").bind("click", bind_btn_et2);
            },
            error : function(r) {
                alert("抱歉,系统繁忙,请您稍后重试!");
                $("#phone7").bind("click", bind_btn_et2);
            }
        });//end ajax
    });//end click
    

    });

    function timeCountDown() { //加时函数

    if (seconds > 0) { //如果不到5分钟
    $("#get_code").html(seconds + "秒重新获取");
    seconds--; //时间变量自减1
    setTimeout("timeCountDown()", 1000); //设置1000毫秒以后执行一次本函数
    } else {
    $("#get_code").bind("click", code_btn_et1);
    $("#get_code").html("获取验证码");
    }
    };

    package servlet;

    import java.io.IOException;
    import java.io.PrintWriter;
    import java.util.Enumeration;
    import java.util.Random;

    import javax.servlet.ServletException;
    import javax.servlet.annotation.WebServlet;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;

    import org.apache.commons.lang.StringUtils;
    //import org.slf4j.Logger;
    //import org.slf4j.LoggerFactory;
    import org.xml.sax.SAXException;

    import com.sinovatech.ntf.send.NtfplatService;

    import domain.BindPhoneBean;
    import service.QiangkaBindService;
    import util.Utils;
    @WebServlet("/QiangkaBindServlet")
    public class QiangkaBindServlet extends HttpServlet {

    private static final long serialVersionUID = 7599540073445710243L;
    //private static Logger log = LoggerFactory.getLogger(QiangkaBindServlet.class);
    
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
    
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        try {
    
            request.setCharacterEncoding("UTF-8");
            response.setCharacterEncoding("UTF-8");
            response.setContentType("text/html; charset=utf-8");
            String openId = request.getParameter("openId");
            String typeStr = request.getParameter("type");
    
            //log.info("----WangkaBindServlet-----openId:" + openId + "------typeStr:" + typeStr);
            String respJson = "{ \"code\":\"1\" , \"desc\":\"服务器访问失败,请稍后重试!\" }";
    
            if (openId != null && !"".equals(openId) && typeStr != null && !"".equals(typeStr)) {
    
                int type = Integer.parseInt(typeStr);
                if (type == 1) {// 判断是否绑定
                    respJson = "{\"code\":\"1\" ,\"isAppoint\":false}";
                    // String phone = request.getParameter("phone");
                    // if (phone != null && !phone.equals("")) {
                    // boolean isSichuan =
                    // QiangkaBindService.getInstance().checkSichuan(phone);
                    // log.info("\n=====是否四川用户:" + isSichuan);
                    // boolean isSichuan=true;//mock
                    boolean isAppoint = false;
                    // if(isSichuan==true){
                    isAppoint = QiangkaBindService.getInstance().checkAppoint(openId);
                    // }
                    //log.info("\n=====是否已经绑定用户:" + isAppoint);
                    respJson = "{\"code\":\"0\" ,\"isAppoint\":" + isAppoint + "}";
                    // respJson = "{\"code\":\"0\"
                    // ,\"isUsim\":"+false+",\"isSichuan\":"+true+"}";//mock
                    //log.info("---respJson:" + respJson);
                    // }
                } else if (type == 4) { // 发送验证码
                    String phone = request.getParameter("phone");
    
                    NtfplatService sendsingle = new NtfplatService();
                    // 业务类别编码
                    String bizCode = "11001";
    
                    // 业务类别名称
                    String bizName = "京东强卡验证码下发";
                    // 任务名称
                    String taskName = "京东强卡验证码下发";
    
                    // // 随机生成验证码
                    // Random random = new Random();
                    // int yzm = random.nextInt(899999);
                    // yzm += 100000;
    
                    // 短信内容
                    // String content = "您的验证码是:" + yzm + "[京东强卡]";
    
                    // 手机号
                    // String target="";
    
                    if (phone != null && !"".equals(phone)) {
                        // boolean isSichuan =
                        // QiangkaBindService.getInstance().checkSichuan(phone);
                        // boolean isSichuan = true;//mock
                        // log.info("\n=====亲友是否四川用户:" + isSichuan);
                        // boolean isUsim=false;
                        boolean success = false;// 发短信是否成功
                        boolean isAppoint = false;// 这个人是否绑定
                        // BindPhoneBean bpBean0 =
                        // QiangkaBindService.getInstance().queryBindPhoneInfoByOpenId(openId,phone);
                        /*
                         * if(bpBean0 !=
                         * null&&bpBean0.getCode()!=0&&bpBean0.getIsBind()==1||
                         * bpBean0 != null&&bpBean0.getCode()==0){//这个朋友已经绑定了
                         * isAppoint=true; }else {
                         */
                        // if(isSichuan==true){
                        // isUsim=QiangkaBindService.getInstance().checkUsim(phone);
                        // log.info(" isUsim="+isUsim);
                        // isUsim=false;
                        // if(isUsim){//发短信验证码 //检查是否在库中,在库中的不是USIM卡
    
                        // BindPhoneBean bpBean0 =
                        // QiangkaBindService.getInstance().queryBindPhoneInfoByOpenId(openId);
                        // if(bpBean0 !=
                        // null&&bpBean0.getCode()!=0&&bpBean0.getIsBind()==1){//这个人已经绑定了
                        // isAppoint=true;//是否绑定该手机号
                        // }else{
                        // isAppoint=false;//是否绑定该手机号
                        // }
                        // log.info("\n=====是否绑定用户:" + isAppoint);
                        isAppoint = QiangkaBindService.getInstance().checkAppoint(openId);
                        if (!isAppoint) {//// 没绑定,绑定一下
                            int code = Utils.buildRandom(6);// 生成验证码
                            //log.info("^^^^^^^^^^^^^^^^^^^^^强卡服务绑定^^^^^^^^^^^^^^^^^^^^^验证码是:" + code);
                            // String smsMsg =
                            // "您的验证码是:"+code+"(10分钟内有效),如非本人操作,请忽略本短信。";
                            String smsMsg = "您的强卡服务微信公众号验证码是:" + code + "(10分钟内有效),如非本人操作,请忽略本短信";
                            // boolean
                            // sendRs=SendSmsNetEngine.getInstance().sendSms(phone,smsMsg);
                            try {
                                int sendRs = sendsingle.sendSingle(bizCode, bizName, taskName, smsMsg, phone);
                                System.out.println(sendRs + ":京东强卡验证码下发成功");
                            } catch (SAXException e) {
                                e.printStackTrace();
                            }
                            BindPhoneBean bpBean = new BindPhoneBean();
                            bpBean.setOpenId(openId);
                            //log.info("openId=" + openId);
                            bpBean.setPhone(phone);
                            bpBean.setCode(code);
                            bpBean.setIsBind(0);
                            bpBean.setStatusBind(1);
                            QiangkaBindService.getInstance().saveOrUpdateBindPhone(bpBean); // 存入数据库
                            success = true;
                        }
                        // }
                        // }
                        /* } */
                        /*
                         * respJson = "{\"code\":\"0\" ,\"isUsim\":"
                         * +isUsim+",\"isSichuan\":"+isSichuan+",\"isAppoint\":"
                         * +isAppoint+",\"success\":"+success+"}";
                         */
                        respJson = "{\"code\":\"0\" ,\"isAppoint\":" + isAppoint + ",\"success\":" + success + "}";
                    } else {
                        respJson = "{\"code\":\"1\",\"msg\":\"请输入正确的手机号码!\"}";
                    }
                } else if (type == 5) { // 校验验证码,若正确则绑定
                    String phone = request.getParameter("phone");
                    if (phone != null && !"".equals(phone)) {
                        // boolean isSichuan = false;
                        // log.info("\n=====亲友是否四川用户:" + isSichuan);
                        // boolean isUsim=false;
                        // boolean isAppoint=false;//这个朋友是否绑定
                        boolean success = false;// 绑定是否成功
                        boolean rightYzm = true;// 验证码是否正确
                        // boolean isFirst=false;//是否首次绑定
                        // isFirst=QiangkaBindService.getInstance().checkFirst(openId);//是否首次绑定
                        BindPhoneBean bpBean = QiangkaBindService.getInstance().queryBindPhoneInfoByOpenId(openId);
                        boolean isAppoint = false;// 这个人是否绑定
                        isAppoint = QiangkaBindService.getInstance().checkAppoint(openId);
    
                        if (!isAppoint) {// 这个朋友已经绑定了
                            // isSichuan =
                            // QiangkaBindService.getInstance().checkSichuan(phone);
                            // isSichuan=true;
                            // if(isSichuan==true){
                            // isUsim=QiangkaBindService.getInstance().checkUsim(phone);//检查是否在库中,在库中的不是USIM卡
                            // isUsim=false;
                            // if(isUsim){//不是Usim卡,检查短信验证码是否正确
                            String codeStr = request.getParameter("yzm");
                            //log.info("codeStr=" + codeStr);
                            if (codeStr != null && !"".equals(codeStr)) {
                                int code = Integer.parseInt(codeStr);
                                //log.info("code == bpBean.getCode()" + (code == bpBean.getCode()));
                                if (code == bpBean.getCode()) {
                                    bpBean.setOpenId(openId);
                                    bpBean.setPhone(phone);
                                    bpBean.setIsBind(1);
                                    bpBean.setStatusBind(0);
                                    bpBean.setPhoneType(1);// 号码类型 0 未知 1四川联通 2
                                                            // 非四川联通 3 移动号码 4
                                                            // 电信号码
    
                                    success = QiangkaBindService.getInstance().saveOrUpdateBindPhone(bpBean); // 存入数据库
                                    if (success) {
                                        /*
                                         * String[]
                                         * awards=QiangkaBindService.getInstance
                                         * ().getAward(openId);
                                         * if(awards[0]==null&&awards[1]==null){
                                         * QiangkaBindService.getInstance().
                                         * saveAward(openId); }
                                         * if(isFirst){//首次绑定给奖品
                                         * QiangkaBindService.getInstance().
                                         * saveAward(openId); }
                                         */
                                    }
                                } else {
                                    rightYzm = false;
                                }
                            }
                            // }
                            // }
                        } else {
                            rightYzm = false;
                        }
                        /*
                         * respJson = "{\"code\":\"0\" ,\"isUsim\":"
                         * +isUsim+",\"isSichuan\":"+isSichuan
                         * +",\"isAppoint\":"+isAppoint+",\"success\":"+success+
                         * ",\"rightYzm\":"+rightYzm+"}";
                         */
                        respJson = "{\"code\":\"0\" ,\"isAppoint\":" + isAppoint + ",\"success\":" + success
                                + ",\"rightYzm\":" + rightYzm + "}";
                    } else {
                        respJson = "{\"code\":\"1\",\"msg\":\"请输入正确的手机号码!\"}";
                    }
                } else if (type == 6) {// 解除绑定
                    BindPhoneBean bpBean = QiangkaBindService.getInstance().queryBindPhoneInfoByOpenId(openId);
                    boolean isAppoint = false;// 这个人是否绑定
                    // isAppoint=QiangkaBindService.getInstance().checkAppoint(openId);
                    // if(isAppoint){//这个朋友已经绑定了
                    bpBean.setIsBind(0);
                    bpBean.setStatusBind(1);
                    bpBean.setPhoneType(0);// 号码类型 0 未知 1四川联通 2 非四川联通 3 移动号码 4
                                            // 电信号码
                    boolean success = QiangkaBindService.getInstance().saveOrUpdateBindPhone(bpBean); // 存入数据库
                    respJson = "{\"code\":\"0\" ,\"isAppoint\":" + isAppoint + ",\"success\":" + success + "}";
                    // }else{//这个朋友未绑定
                    // respJson = "{\"code\":\"0\"
                    // ,\"isAppoint\":"+isAppoint+",\"success\":"+false+"}";
                    // }
                } else if (type == 7) { // 无验证码绑定-亚联
                    String phone = request.getParameter("phone");
                    if (phone != null && !"".equals(phone)) {
                        boolean success = false;// 绑定是否成功
                        // boolean rightYzm=true;//验证码是否正确
                        // BindPhoneBean bpBean =
                        // QiangkaBindService.getInstance().queryBindPhoneInfoByOpenId(openId);
                        BindPhoneBean bpBean = new BindPhoneBean();
                        // boolean isAppoint=false;//这个人是否绑定
                        // isAppoint=QiangkaBindService.getInstance().checkAppoint(openId);
                        // if(!isAppoint){//这个朋友已经绑定了
                        // String codeStr = request.getParameter("yzm");
                        // log.info("codeStr="+codeStr);
                        // if(codeStr != null && !"".equals(codeStr)){
                        // int code = Integer.parseInt(codeStr);
                        // log.info("code == bpBean.getCode()"+(code ==
                        // bpBean.getCode()));
                        // if(code == bpBean.getCode()){
                        bpBean.setOpenId(openId);
                        bpBean.setPhone(phone);
                        bpBean.setIsBind(1);
                        bpBean.setStatusBind(0);
                        bpBean.setPhoneType(1);// 号码类型 0 未知 1四川联通 2 非四川联通 3 移动号码
                                                // 4 电信号码
                        success = QiangkaBindService.getInstance().saveSpecBindPhone(bpBean); // 存入数据库
                        // }else{
                        // rightYzm=false;
                        // }
                        // }
                        // }else{
                        // rightYzm=false;
                        // }
                        respJson = "{\"code\":\"0\",\"success\":" + success + "}";
    
                    } else {
                        respJson = "{\"code\":\"1\",\"success\":false}";
                    }
                }
            }
            //log.info("-----respJson:" + respJson);
            PrintWriter out = response.getWriter();
            out.println(respJson);
            out.flush();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    @SuppressWarnings("rawtypes")
    public static boolean validateRequest(HttpServletRequest request) {
        String referer = "";
        boolean referer_sign = true;// true 站内提交,验证通过 //false 站外提交,验证失败
        Enumeration headerValues = request.getHeaders("referer");
        while (headerValues.hasMoreElements()) {
            referer = (String) headerValues.nextElement();
        }
        // 判断是否存在请求页面
        if (StringUtils.isBlank(referer))
            referer_sign = false;
        else {
            // 判断请求页面和getRequestURI是否相同
            String servername_str = request.getServerName();
            if (StringUtils.isNotBlank(servername_str)) {
                int index = 0;
                if (StringUtils.indexOf(referer, "https://") == 0) {
                    index = 8;
                } else if (StringUtils.indexOf(referer, "http://") == 0) {
                    index = 7;
                }
    
                if (referer.length() - index < servername_str.length()) {// 长度不够
                    referer_sign = false;
                } else { // 比较字符串(主机名称)是否相同
                    String referer_str = referer.substring(index, index + servername_str.length());
                    if (!servername_str.equalsIgnoreCase(referer_str))
                        referer_sign = false;
                }
            } else
                referer_sign = false;
        }
        return referer_sign;
    }
    

    }

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 用C语言输入方程怎么
  • ¥15 网站显示不安全连接问题
  • ¥15 github训练的模型参数无法下载
  • ¥15 51单片机显示器问题
  • ¥20 关于#qt#的问题:Qt代码的移植问题
  • ¥50 求图像处理的matlab方案
  • ¥50 winform中使用edge的Kiosk模式
  • ¥15 关于#python#的问题:功能监听网页
  • ¥15 怎么让wx群机器人发送音乐
  • ¥15 fesafe材料库问题