jsp中script:
$.ajax({
type: "POST",timeout: 3000,
async: false,
cache: false,
data:{id:id},//参数
url: "/Txd/login/checkId",
success: function (data){
var obj = eval('(' + data+ ')');//将json串转化成jason
if(obj.error_code!="0"){
document.getElementById("chId").innerHTML="请输入正确的身份证号!";
}
if(obj.error_code=="0"){
document.getElementById("chId").innerHTML="";
}
},
error : function() {
document.getElementById("chId").innerHTML="请输入正确的身份证号!";
}
});
Controller中:
@ResponseBody //这一行很重要
@RequestMapping("/checkId")
public String checkId(String id) throws Exception{
String result=new CheckId().checkIdNumber(id);
return result;
}