zoukankan      html  css  js  c++  java
  • jquery.validationEngine+ajax验证

    利用jquery.validationEngine ajax验证后台id是否已存在

    前台jquery validation框架验证

    jsp:

    <link rel="stylesheet" type="text/css" href="<%=path%>/js/css/validationEngine.jquery.css"/>
    <script type="text/javascript" src="<%=path%>/js/jquery/jquery-1.4.2.min.js"></script>
    <script type="text/javascript" src="<%=path%>/js/validation/jquery.validationEngine-cn.js"></script>
    <script type="text/javascript" src="<%=path%>/js/validation/jquery.validationEngine.js"></script>
    
     <input  type="text" name="item.entry" id="item_entry" class="validate[required,custom[onlyNumber],ajax[ajaxItemNoCall],length[0,4]] text-input" size="10"/></td>

     

    jquery.validationEngine-cn.js

                    "ajaxItemNoCall": {
    	                "url": "validateItemNo",
    				    "alertText": "* ID已被使用",
    				    "alertTextOk": "*ID可以使用",
    				    "alertTextLoad": "* 检查中, 请稍候..."
    	            }

     

    ItemAction.java

     

    @Action(results = {@Result(type="json")}, params = { "excludeProperties", "validateReturn"}, value="validateItemNo")
    	public String validateItemNo() throws Exception{
    		ActionContext ct = ActionContext.getContext();
    		HttpServletRequest request= 
    			(HttpServletRequest)ct.get(ServletActionContext. HTTP_REQUEST ); 
    		String validateId = request.getParameter("fieldId");
    		String validateValue = request.getParameter("fieldValue");
    		int valiValue = Integer.parseInt(validateValue);
    		   
    			item = itemService.findItemById(valiValue);
    				if(item.getEntry() != valiValue){
    					validateReturn[0] = validateId;
    					validateReturn[1] = true;
    					validateReturn[2] = "可以使用";
    				}else {
    					validateReturn[0] = validateId;
    					validateReturn[1] = false;
    					validateReturn[2] = "在指定ID已经存在";
    				}
    		return "success";
    	}

    ---------------------------------------------------------------------------------------------------------------------------------
    copyright:http://www.cnblogs.com/anee/
  • 相关阅读:
    学习Hadoop不错的系列文章(转)
    浏览器的渲染原理简介
    大数据人才缺乏,你准备好了吗?
    SVN分支与合并透析
    Windows下SVN服务端(Subversion)及客户端(TortoiseSVN)详细安装教程
    maven2介绍(转)
    eclipse安装velocity插件(转)
    为大数据时代做好准备——来自《大数据的冲击》一书精彩片段(转)
    【VB】Format 格式化日期时间数字函数详解
    获取本机ID和电脑名称
  • 原文地址:https://www.cnblogs.com/anee/p/2675834.html
Copyright © 2011-2022 走看看