当前位置:首页 > 开发 > Web前端 > Jquery > 正文

jquery.vlidate的remote用法

发表于: 2012-05-10   作者:chenwes   来源:转载   浏览次数:
摘要: <script type="text/javascript"> $.validator.setDefaults({ submitHandler: function() { form.submit(); } }); $().ready(function() { $("#form").validate({
<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
	}

}


jquery.vlidate的remote用法

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

编辑推荐
在开发中经常要调试定位bug,本地开发很自然开启debug,但是某些特殊情况下,代码只能在服务器上才
1. 介绍: Remote Blob Store(RBS)是一种把大容量二进制数据文件(Blob)从数据库转移到文件存储系统
Most network programming is done by writing application programs that call system-provided fu
1.SharedObject可以跟踪和广播消息,连接到SharedObject中的其中任何一个客户端改变了SharedObject
欢迎交流转载,请注明出处:http://www.cnblogs.com/shizhongtao/p/3487128.html 1.配置及说明 jar
A method and apparatus for managing remote devices. In one embodiment of the present inventio
1、下载此软件,网上的下载地址很多 2、在All Sessions中右键,出现Add菜单,移动至Add By Sessions
WebKit Remote Debugging Posted by Pavel Feldman on Monday, May 9th, 2011 at 8:13 am As you mi
使用Remote debug 能够在浏览器直接调试手机里的html,非常方便。相关资料如下 http://adamlu.com/?
January 18, 2011 By default the remote errors property in SQL Server Reporting Services is se
版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号