email ajax傳輸資料去重和非空判斷

來源:互聯網
上載者:User

標籤: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傳輸資料去重和非空判斷

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.