乱码乱a∨中文字幕,在线免费激情视频,亚洲欧美久久夜夜潮,国产在线网址

  1. <sub id="hjl7n"></sub>

    1. <sub id="hjl7n"></sub>

      <legend id="hjl7n"></legend>

      當(dāng)前位置:首頁 >  站長 >  編程技術(shù) >  正文

      利用Ajax檢測用戶名是否被占用的完整實例

       2020-12-16 11:13  來源: 腳本之家   我來投稿 撤稿糾錯

        阿里云優(yōu)惠券 先領(lǐng)券再下單

      這篇文章主要給大家介紹了關(guān)于如何利用Ajax檢測用戶名是否被占用的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

      適合人群:Ajax和jQuery入門

      采用Ajax實現(xiàn)用戶名驗證

      使用jQuery給出提示信息

      用戶注冊的時候,使用Ajax實現(xiàn)檢測用戶名是否已經(jīng)被注冊過,很多細(xì)節(jié)沒有實現(xiàn),給大家做個簡單普及。

      <%@ page language="java" contentType="text/html; charset=utf-8"
      pageEncoding="utf-8"%>
      <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
      <html>
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      <title>用戶注冊頁面</title>
      <script src="https://libs.baidu.com/jquery/1.8.3/jquery.min.js"></script>
      <script type="text/javascript">
      var xmlHttp;
      function createXMLHttpRequest(){
      if(window.XMLHttpRequest){
      xmlHttp = new XMLHttpRequest();
      }else if(window.ActiveXObject){
      xmlHttp = new ActiveXObject("Microsoft.XMLHttp");
      }
      }
      function validate(account){
      createXMLHttpRequest();
      xmlHttp.open("Get","ValidateServlet?account="+account,true);
      xmlHttp.onreadystatechange = callback;
      xmlHttp.send(null);
      }
      function callback(){
      if(xmlHttp.readyState==4){
      if(xmlHttp.status==200){
      var text = xmlHttp.responseText;
      if(text=="true"){
      //document.getElementById("msg").innerHTML = "該手機(jī)號已經(jīng)被注冊過";
      $("#msg").text("該手機(jī)號已經(jīng)被注冊");
      $("#sub").attr("disabled","true");//添加disabled屬性,讓按鈕不可用
      }else{
      //document.getElementById("msg").innerHTML = "";
      $("#msg").text("");
      $("#sub").removeAttr("disabled");//移除disabled屬性,讓按鈕可用

      }
      }else{
      alert("請求失敗,錯誤碼="+xmlHttp.status);
      }
      }
      }
      function checkInfo(){
      var account = $("#account").val();
      var pwd1 = $("#pwd1").val();
      var pwd2 = $("#pwd2").val();
      if(account==""||account==null){
      $("#msg").text("賬號不能為空");
      $("#sub").attr("disabled","true");
      return false;
      }
      if(pwd1==""||pwd1==null||pwd2==""||pwd2==null||pwd1!=pwd2){
      $("#info").text("密碼不能為空或者兩次密碼不一致");
      $("#sub").attr("disabled","true");
      return false;
      }
      $("#msg").text("");
      $("#info").text("");
      $("#sub").removeAttr("disabled");
      }
      function submit(){
      checkInfo();
      $("#reg").submit();
      }

      </script>
      </head>
      <body>
      <form id="reg" name="reg" action="RegisterServlet" method="post">
      賬號:<input type="text" name="account" id="account" onblur="validate(this.value);">
      <span id="msg" style="color:red">請輸入手機(jī)號</span><br>
      密碼:<input type="password" id="pwd1" name="password1" onblur="checkInfo();"><br>
      確認(rèn)密碼:<input type="password" id="pwd2" name="password2" onblur="checkInfo();">
      <span id="info" style="color:red"></span><br>
      <input type="button" id="sub" value="提交" onclick="submit();">
      </form>
      </body>
      </html>

      下面是ValidateServlet模擬實現(xiàn),沒有做真正的數(shù)據(jù)庫表數(shù)據(jù)檢測,大家自行完成。

      package com.ambow.servlet;

      import java.io.IOException;
      import java.io.PrintWriter;

      import javax.servlet.ServletException;
      import javax.servlet.annotation.WebServlet;
      import javax.servlet.http.HttpServlet;
      import javax.servlet.http.HttpServletRequest;
      import javax.servlet.http.HttpServletResponse;

      @WebServlet("/ValidateServlet")
      public class ValidateServlet extends HttpServlet {
      private static final long serialVersionUID = 1L;
      public ValidateServlet() {
      super();
      }
      protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      PrintWriter pw = response.getWriter();
      String account = request.getParameter("account");
      System.out.println("account"+account);
      if("123".equals(account)) {
      pw.print("true");
      }else {
      pw.print("false");
      }
      }
      protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      doGet(request, response);
      }
      }

      到此這篇關(guān)于利用Ajax檢測用戶名是否被占用的文章就介紹到這了,更多相關(guān)Ajax檢測用戶名被占用內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

      來源:腳本之家

      鏈接:https://www.jb51.net/article/201504.htm

      申請創(chuàng)業(yè)報道,分享創(chuàng)業(yè)好點(diǎn)子。點(diǎn)擊此處,共同探討創(chuàng)業(yè)新機(jī)遇!

      相關(guān)標(biāo)簽
      ajax

      相關(guān)文章

      • Ajax實現(xiàn)頁面無刷新留言效果

        這篇文章主要為大家詳細(xì)介紹了Ajax實現(xiàn)頁面無刷新留言效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

        標(biāo)簽:
        ajax
      • AJAX檢測用戶名是否存在的方法

        這篇文章主要為大家詳細(xì)介紹了AJAX檢測用戶名是否存在,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

        標(biāo)簽:
        ajax
      • 使用AJAX 包含正則表達(dá)式 驗證用戶登錄的步驟

        這篇文章主要介紹了使用AJAX(包含正則表達(dá)式)驗證用戶登錄的步驟,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下

        標(biāo)簽:
        ajax
      • ajax使用formdata上傳文件流

        這篇文章主要為大家詳細(xì)介紹了ajax使用formdata上傳文件流,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

        標(biāo)簽:
        ajax
      • Spring MVC+ajax進(jìn)行信息驗證的方法

        AJAX不是新的編程語言,而是一種使用現(xiàn)有標(biāo)準(zhǔn)的新方法。這篇文章主要介紹了SpringMVC+ajax進(jìn)行信息驗證,需要的朋友可以參考下

        標(biāo)簽:
        ajax

      熱門排行

      信息推薦