jquery.vlidate的remote用法

编程技术  /  houtizong 发布于 3年前   81
<script type="text/javascript">       $.validator.setDefaults({submitHandler: function() { form.submit(); }});$().ready(function() {  $("#form").validate({     rules:     {     username:{     remote: {                                   url: "/checkun",//验证地址,这里用的是servlet可以用jsp或者php      type:'POST',//大写      dataType:'json',     data:{ username:function(){return $('#username').val()}}           },required: true,minlength:4},     password:{required: true,minlength:4,maxlength:16},     password2:{required: true,minlength:4,equalTo:"#password"}     },     messages:     {     username:{required: "请输入用户名",minlength: "用户名至少四位数",remote:"用户名已经存在"},     password:{required: "请输入密码",minlength: "密码长度为4~16",maxlength: "不超过16位"},     password2:{required: "重复密码",minlength:"长度为4~16",maxlength: "不超过16位",equalTo: "两次输入不同"}     }     });   });


  <body>   <form id="form" name="form" method="post" action="user.do?method=adduser">   <div id="main">     <p>注册</p>     <p>      <label for="username">用户名</label>     <input class="c" name="username" type="text" id="username"  onblur="validatorloginName();" />     </p><div id="checkresult" ></div>     <p>     <label for="password">密码</label>      <input class="c" name="password" type="password" id="password"   />     </p>     <p>     <label for="password2">重复密码</label>     <input class="c" name="password2" type="password" id="password2"  />     </p>     <p>     <input type="Submit" name="Submit" value="提交" id="sub" onclick="check();"  />     <input type="reset" name="reset" value="重置" id="sub" />     </p>      </div>   </form>  </body>


下面是servlet
package servlet;import java.io.IOException;import java.io.PrintWriter;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import daoimlp.UserInfoImpl;public class Validate extends HttpServlet {public Validate() {super();}public void destroy() {super.destroy(); // Just puts "destroy" string in log// Put your code here}public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {response.setContentType("text/html");response.setCharacterEncoding("UTF8");String username = request.getParameter("username").toString();UserInfoImpl userimpl = new UserInfoImpl();System.out.println("dovalidate");PrintWriter out = response.getWriter();if(userimpl.cheakUser(username)){out.println("true");//只能是true和false 如果不行的话就把双引号去了System.out.print("1");}else{out.println("false");System.out.print("2");}out.close();}public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {this.doGet(request, response);}public void init() throws ServletException {// Put your code here}}

请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!

留言需要登陆哦

技术博客集 - 网站简介:
前后端技术:
后端基于Hyperf2.1框架开发,前端使用Bootstrap可视化布局系统生成

网站主要作用:
1.编程技术分享及讨论交流,内置聊天系统;
2.测试交流框架问题,比如:Hyperf、Laravel、TP、beego;
3.本站数据是基于大数据采集等爬虫技术为基础助力分享知识,如有侵权请发邮件到站长邮箱,站长会尽快处理;
4.站长邮箱:[email protected];

      订阅博客周刊 去订阅

文章归档

文章标签

友情链接

Auther ·HouTiZong
侯体宗的博客
© 2020 zongscan.com
版权所有ICP证 : 粤ICP备20027696号
PHP交流群 也可以扫右边的二维码
侯体宗的博客