静态页面ajax

 1.静态页面html

$.ajax({
                type:"get",
                url:"http://localhost:8080/app/register/sendSMS",//请求地址必须带http协议
                data:{"phone":phone},
                async:false,//是否异步
                dataType: "jsonp",//固定格式
                jsonp: "callback",//固定格式
                jsonpCallback:"flightHandler",//固定格式
                success:function(result){
                    if(result==0){
                        var object=document.getElementById("btn");
                        time(object);
                        console.log(document.getElementById("btn"));
                        alert("请查看验证码");
                    }else if(result==1){
                        alert("手机号已注册");
                        window.location.href = "download.html";
                    }else{
                        alert("请输入正确手机号");
                    }
                },
                error:function(result){
                    alert("数据获取失败");
                }
            });
        }

2.java回调java

public String ajax(){
    String str="";//回调的字符串
    String json= JSON.toJSONString(str);
        System.out.println(json);
        return "flightHandler("+json+")"//固定格式
}
相关文章
相关标签/搜索