jquery.validate通过remote来实现ajax验证范例
2018-01-25 14:59
543 查看
jquery.validate可谓是个强大的表单验证插件,当然也完美支持ajax验证,这样可以方便、快速来实现检查用户名等等是否存在。
html/js源码部分:
[html] view
plain copy
<meta charset="utf-8" />
<!DOCTYPE html>
<html>
<head>
<title>Submit a form via AJAX</title>
<script src="js/jquery.min.js"></script>
<script src="http://static.runoob.com/assets/jquery-validation-1.14.0/dist/jquery.validate.min.js"></script>
<script src="http://static.runoob.com/assets/jquery-validation-1.14.0/dist/localization/messages_zh.js"></script>
</head>
<body>
<form action="" name="infos" id="infos">
<p>用户名:<input type="text" name="username" id="username" /></p>
<p><input type="submit" name="sub" /></p>
</form>
<script type="text/javascript">
$(function(){
$('#infos').validate({
debug:false,
onkeyup:false,
rules:{
username:{
required:true,
remote:{
type:"POST",
url:"01.php", //请求地址
data:{
username:function(){ return $("#username").val(); }
}
}
}
},
messages:{
username:{
required:"用户名必填",
remote:"用户名已存在"
}
},
submitHandler:function(form){
alert("验证通过");
}
});
});
</script>
</body>
</html>
@RequestMapping(value="/check")
@ResponseBody
public boolean check(HttpServletRequest request) throws Exception{
String code = request.getParameter("code").trim();
System.out.println("code = " + code);
return false;
}
html/js源码部分:
[html] view
plain copy
<meta charset="utf-8" />
<!DOCTYPE html>
<html>
<head>
<title>Submit a form via AJAX</title>
<script src="js/jquery.min.js"></script>
<script src="http://static.runoob.com/assets/jquery-validation-1.14.0/dist/jquery.validate.min.js"></script>
<script src="http://static.runoob.com/assets/jquery-validation-1.14.0/dist/localization/messages_zh.js"></script>
</head>
<body>
<form action="" name="infos" id="infos">
<p>用户名:<input type="text" name="username" id="username" /></p>
<p><input type="submit" name="sub" /></p>
</form>
<script type="text/javascript">
$(function(){
$('#infos').validate({
debug:false,
onkeyup:false,
rules:{
username:{
required:true,
remote:{
type:"POST",
url:"01.php", //请求地址
data:{
username:function(){ return $("#username").val(); }
}
}
}
},
messages:{
username:{
required:"用户名必填",
remote:"用户名已存在"
}
},
submitHandler:function(form){
alert("验证通过");
}
});
});
</script>
</body>
</html>
@RequestMapping(value="/check")
@ResponseBody
public boolean check(HttpServletRequest request) throws Exception{
String code = request.getParameter("code").trim();
System.out.println("code = " + code);
return false;
}
相关文章推荐
- jquery.validate通过remote来实现ajax验证范例
- jquery.validate通过remote来实现ajax验证范例
- 在JQuery的validate功能中使用remote实现Ajax功能后台验证
- jQuery validate插件实现ajax验证重复的2种方法
- jquery.validate 验证(支持前台js验证通过,然后ajax后台数据校验)二
- jQuery validate插件实现ajax验证重复的2种方法
- jquery.validate的ajax方式验证[可以一个控件下一次传递多个参数,已经成功通过验证]
- 通过jquery validate和bootstrap实现表单后面提示打钩或打叉的效果和真实的表单验证
- ASP.NET jQuery 食谱12 (通过使用jQuery validation插件简单实现用户注册页面验证功能)
- jQuery插件Validate实现自定义表单验证
- 使用jQuery Validate实现表单验证
- jquery validate如何不提交表单就做验证(ajax提交数据)
- jQuery Validate 插件验证,,返回不同信息(json remote)自定义
- jquery-validate remote验证,返回不同的消息内容
- jQuery-EasyUI validatebox+正则表达式实现验证
- Jquery与ajax结合实现验证用户名(邮箱是否)已经被注册过
- 使用jQuery实现AJAX帐号验证效果
- 用jquery validate插件实现强密码验证
- jQuery 与 AJAX 实现失去焦点验证用户名是否合格
- struts2框架通过jQuery实现AJAX应用