码迷,mamicode.com
首页 > Web开发 > 详细

email ajax传输数据去重和非空判断

时间:2016-12-12 20:18:18      阅读:260      评论:0      收藏:0      [点我收藏+]

标签:username   response   blur   request   word   map   bsp   throws   str   

前台:

 

 <td class="in-ctt" width="35%" ><input type="text" name="email" id="email" required="required" /><div id="content"></div>

 

ajax:

$(document).ready(function(){

$("#email").blur(function(){
$("#email").css("background-color","#D6D6FF");
$.ajax({type:"post",url:"check_email.do",data:{‘email‘:$("#email").val()},
success:function(data){

if(data==2){
$("#content").html("<p>邮箱已经存在</p>");
$(".btn").attr("disabled", true);
}
if(data==1)
{
$("#content").html("<p></p>");
$(".btn").attr("disabled", false);
}
if(data==13)
{
$("#content").html("<p>邮箱不能为空</p>");
$(".btn").attr("disabled", true);
}
}
});
});
});

后台数据处理:

@RequestMapping("check_email.do")
public void checkEmail(HttpServletRequest request, HttpServletResponse response) throws IOException {
PrintWriter out= response.getWriter();
String email= request.getParameter("email");
// 检查数据库是否重名
boolean exist = service.emailExist(email);
if (!exist) {
Servlets.writeHtml(response, "1");
} else {
Servlets.writeHtml(response, "2");
}
if(StringUtils.isBlank(email))
Servlets.writeHtml(response, "3");
out.close();
/*if (StringUtils.isBlank(email)) {
Servlets.writeHtml(response, "false");
return;
}
if (StringUtils.equals(email, original)) {
Servlets.writeHtml(response, "true");
return;
}
// 检查数据库是否重名
boolean exist = service.emailExist(email);
if (!exist) {
Servlets.writeHtml(response, "true");
} else {
Servlets.writeHtml(response, "false");
}*/
}

元生后台:

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html:charset=utf-8");
response.setCharacterEncoding("utf-8");
PrintWriter out= response.getWriter();
request.setCharacterEncoding("utf-8");
String username= request.getParameter("username");
String password= request.getParameter("password");

if(username.equals("洪帆"))
{
/* out.println("<p>"+username+"</p>");*/
out.println("1");

/*out.println("<p>"+password+"</p>");
out.println("<p>"+"用户名准确"+"</p>");*/

}else{
out.print(username);
out.print("用户名或密码错误");
}
out.close();



}

 

jquery校验textarea必填

<head>
<script type="text/javascript">
$("#sub1).click(function(){
var text1=$("#text1").val();

if(text1==""){

alert("不能为空!");

$("#text1").select();

$("#text1").focus();

}else{
$("#form1").submit();
}

})
</script>

</head>
<body>
<form id="form1" method="post" action="">
<input type=text id="text1"/>
<input type="submit" id="sub1" value="提交">
</form>
</body>

 

email ajax传输数据去重和非空判断

标签:username   response   blur   request   word   map   bsp   throws   str   

原文地址:http://www.cnblogs.com/hongfan/p/6165556.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!