提交表单时,异步验证
var name = $("#name").val();
$.ajax({
type: "Post",url: "router-agent!checkName.do",
data: "routerAgent.name="+encodeURIComponent(name),//字符格式转换,如果是汉字之类 的参数需要转码
dataType:"text",
async:false,
success: function(result){
if(result != null && result != ""){
if(result=="yes"){
alert("手机号码:"+name+"已经存在");
}else{
loading();
submitForm("addform");
}
}
},
error:function(){
alert("网络连接超时!");
}
});
后台action
public String checkName() throws HtjxException { String result = ""; if (routerAgentService.checkAgentName(routerAgent.getName()) == null) { result = "no"; } else { result = "yes"; } outPrint(result); return null; }
原文链接:https://www.f2er.com/ajax/163703.html