标签:
话不多说,直接上代码
页面head里面的formvalidator验证配置
<script type="text/javascript"> $(document).ready(function() { $.formValidator.initConfig({ formID : "form1", theme : "ArrowSolidBox", wideWord : false, submitOnce : true, onError : function(msg, obj, errorlist) { $("#errorlist").empty(); $.map(errorlist, function(msg) { $("#errorlist").append("<li>" + msg + "</li>") }); alert(msg); }, ajaxPrompt : '有数据正在异步验证,请稍等...' }); $("#name").formValidator({ tipID : "nameTip", onShow : "请输入角色名", onCorrect : "正确" }).inputValidator({ max : 10, onError : "最多输入10个字符!" }).regexValidator({ regExp : "notempty", dataType : "enum", onError : "请输入角色名" }).ajaxValidator({ url:"sysRoleAction_isRoleNameAjax.action", type:"post", dataType:"html", data:{roleName:function(){return $("#name").val()},filterName:"${name}"}, success:function(data){ if(data=="true"){ return false; }else{ return true; } }, buttons: $("#button"), error: function(){alert("服务器没有返回数据,可能服务器忙,请重试");}, onError : "该角色名已经存在!", onWait : "正在对角色名进行合法性校验,请稍候…" }); $("#description").formValidator({tipID : "descriptionTip",empty:true,onShow:"请输入你的描述",onCorrect:"恭喜你,你输对了"}).inputValidator({max:20,onError:"最多输入20个字符"}); }); </script>struts2 action中script验证的方法
public void isRoleNameAjax() throws IOException { /** 文本输出流打印 */ PrintWriter out = response.getWriter(); String roleName = request.getParameter("roleName"); String filterName = request.getParameter("filterName"); boolean findByRoleName = systemRoleService.findByRoleName(roleName,filterName); out.print(findByRoleName); out.flush(); out.close(); }
版权声明:本文为博主原创文章,未经博主允许不得转载。
formValidator向struts2 ajax传参验证
标签:
原文地址:http://blog.csdn.net/wufei151/article/details/46930661