Ajax校验是否重复的实现代码
程序员文章站
2022-03-14 10:56:36
直接贴代码!
一、controller层:
@responsebody
@requestmapping("entityfindbycode")
publ...
直接贴代码!
一、controller层:
@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") list<entity> list = (list<entity>) 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; }
二、html层:
$.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校验是否重复的实现代码,希望对大家有所帮助
上一篇: vue-cli3.0 特性解读