validationengine ajax验证

前端之家收集整理的这篇文章主要介绍了validationengine ajax验证前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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; 
	}

猜你在找的Ajax相关文章