@ResponseBody
@RequestMapping("entityFindByCode")
public String entityFindByCode(Entity bean, HttpSession httpSession, Model m,HttpServletResponse res) throws IOException{
res.setContentType("text/plain; charset=UTF-8");
//res.reset();
//PrintWriter out = res.getWriter();
String data=null;
@SuppressWarnings("unchecked")
ListEntity> list = (ListEntity>) this.service.find("beanByCode", "Entity", new Object[]{bean.getCode()});
if(list.size()==0){
data="YES";
}else{
data="NO";
}
res.getOutputStream().write(data.getBytes());
//out.print(data);
//out.flush();
//out.close();
return data;
}
$.ajax({
url :'entityFindByCode',
type :'post',
dataType :'text',
data :{code:$("#code").val()},//{key,value}
success :function(data) {
if (data == "YES"){
document.getElementById("msg-code").innerHTML = "(fmt:message key='warn.field.required.unique' bundle='${bundle }' />)";
return true;
}
else {
$("#div-code").addClass("has-error");
document.getElementsByName("code")[0].value = "";
//document.getElementsByName("code")[0].setAttribute("placeholder", "fmt:message key='warn.duplicate' bundle='${bundle }' />");
document.getElementById("msg-code").innerHTML = "(fmt:message key='warn.duplicate' bundle='${bundle }' /> !!!)";
return false;
}
}
});
以上所述是小編給大家介紹的Ajax校驗(yàn)是否重復(fù)的實(shí)現(xiàn)代碼,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!