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

Posted 秋分的季节

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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==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传输数据去重和非空判断的主要内容,如果未能解决你的问题,请参考以下文章

Python数据分析pandas去重和替换

SQL Server去重和判断是否为数字——OBJECT_ID的使用

数据库数据插入,空值和非空判断,自动排序,约束主键,唯一约束,外健约束

7数组去重和排序

java空和非空判断

二分法之数组去重和找最小值