jQuery formValidator ajaxValidator url:"servlet" 怎么写??
js脚本如下:
$(document).ready(function(){
//$.formValidator.initConfig({onerror:function(){alert("校验没有通过,具体错误请看错误提示")}});
$.formValidator.initConfig({formid:"form1",onerror:function(msg){alert(msg)}});
$("#username").formValidator({onshow:"请输入帐号",onfocus:"帐号至少6个字符,最多16个字符",oncorrect:"您输入正确"}).inputValidator({min:6,max:16,onerror:"你输入的帐号非法,请确认"}).regexValidator({regexp:"username",datatype:"enum",onerror:"帐号格式不正确"})
.ajaxValidator({
type : "get",
url : "UserServlet?username=0",
datatype : "json",
success : function(data){
if( data == "1" )
{
return true;
}
else
{
return false;
}
},
buttons: $("#button"),
error: function(){alert("服务器没有返回数据,可能服务器忙,请重试");},
onerror : "用户名不可用,请更换用户名",
onwait : "正在对用户名进行合法性校验,请稍候..."
});
$("#userpass").formValidator({onshow:"请输入密码",onfocus:"密码至少6个字符,最多16个字符",oncorrect:"您输入正确"}).inputValidator({min:6,max:16,onerror:"你输入的密码非法,请确认"}).regexValidator({regexp:"username",datatype:"enum",onerror:"密码格式不正确"});
$("#user1").formValidator({onshow:"请输入中文用户名",onfocus:"用户名至少3个汉字,最多8个汉字",oncorrect:"您输入正确"}).inputValidator({min:6,max:16,onerror:"你输入的用户名非法,请确认"}).regexValidator({regexp:"chinese",datatype:"enum",onerror:"用户名格式不正确"});
$("#rand").formValidator({onshow:"请输入验证码",onfocus:"验证码6位",oncorrect:"您输入正确"}).inputValidator({min:6,max:6,onerror:"你输入的验证码非法,请确认"}).regexValidator({regexp:"username",datatype:"enum",onerror:"验证码格式不正确"});
$("#age").formValidator({onshow:"请输入年龄(1-99岁之间)",onfocus:"年龄不能超过99岁",oncorrect:"您输入正确"}).inputValidator({min:1,max:99,type:"value",onerrormin:"你输入的值必须大于等于1",onerror:"年龄必须在1-99之间,请确认"});
$("#email").formValidator({onshow:"请输入邮箱",onfocus:"邮箱至少6个字符,最多30个字符",oncorrect:"恭喜你,你输对了",defaultvalue:"格式为:xxx@xxx.xxx"}).inputValidator({min:6,max:30,onerror:"你输入的邮箱长度非法,请确认"}).regexValidator({regexp:"^([\\w-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([\\w-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$",onerror:"你输入的邮箱格式不正确"});
});
sevlet 如下:
public class UserServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=GBK");
PrintWriter out = response.getWriter();
User user = new User();
String name = request.getParameter("username");
user.setName(name);
Connection conn = OperDB.getConn();
if(OperDB.validate(conn,user)==true)
{
out.print("1");
} //这里应该怎么写啊,我是提交过来用户名然后进入数据库查找,存在的话返回true
}
}
怎么样实现ajaxvalidator的get方法提交到servlet做验证并返回