1、第一种方式通过bean,后台需封装成json数据格式,前台paseJSON();
public void checkCode() {
ResponseMessage rm = new ResponseMessage(true,null);
String hql = "from TblWrPeople t where t.wrPeopleCode='"+code+"' and t.delFlag='"+Constants.DELFLAGA+"'";
List<TblWrPeople> tblWrPeopleList = (List<TblWrPeople>)this.workResService.find(hql);
if (tblWrPeopleList != null && tblWrPeopleList.size() > 0) {
rm.setSuccess(false);
rm.setErrorMsg("数据库中已存在该代号,请重新录入");
this.responseAJAX(JSONObject.fromObject(rm).toString(),getResponse());
}
}
function checkCode() {
var code = $("#wrPeopleCode").val();
$.post('workRes_checkCode.action',{"code":code},function(result){
result = $.parseJSON(result);
if (result.success == false){
alert(result.errorMsg);
$("#wrPeopleCode").val('');
}
});
}
原文链接:https://www.f2er.com/ajax/161642.html