htm代码
<input type="text" value="" class="validate[required,maxSize[20]]" id="dbip" name="dbip"/>
<input type="text" value="" class="validate[ajax[ajaxDbNameCheck]]" id="dbname" name="dbname"/>
jquery.validationEngine.js中加入
"ajaxDbNameCheck" : { "extraDataDynamic" : "#dbip","url" : "dbnameCheck.do","alertText" : "* 该数据库名已经存在","alertTextOk" : "* 数据库名可以使用","alertTextLoad" : "* 正在验证中,请稍等..." }
extraDataDynamic是可选的,就是传递参数到后台用的
@RequestMapping("dbnameCheck.do") public String dbnameCheck(HttpServletRequest request,HttpServletResponse response,ModelMap model){ String fieldId = request.getParameter("fieldId"); String fieldValue = request.getParameter("fieldValue"); String dbip=request.getParameter("dbip"); PrintWriter pw=response.getWriter(); boolean result=dblistServiceNew.findObjectByName(fieldValue,dbip); /** * 结果为true 表存在该结果,grouname不可用 返回false到前台 */ if(result==true){ pw.write("[\"" + fieldId + "\"," + false + "]"); } if(result==false){ pw.write("[\"" + fieldId + "\"," + true+ "]"); } return null; }原文链接:https://www.f2er.com/ajax/165718.html