首页 > 代码库 > email ajax传输数据去重和非空判断

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

前台:

 

 <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=http://www.mamicode.com/=2){
$("#content").html("<p>邮箱已经存在</p>");
$(".btn").attr("disabled", true);
}
if(data=http://www.mamicode.com/=1)
{
$("#content").html("<p></p>");
$(".btn").attr("disabled", false);
}
if(data=http://www.mamicode.com/=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="http://www.mamicode.com/提交">
</form>
</body>

 

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