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+")"//固定格式 }