主頁(yè) > 知識(shí)庫(kù) > 非常實(shí)用的ajax用戶(hù)注冊(cè)模塊

非常實(shí)用的ajax用戶(hù)注冊(cè)模塊

熱門(mén)標(biāo)簽:服務(wù)器配置 科大訊飛語(yǔ)音識(shí)別系統(tǒng) 電子圍欄 阿里云 Linux服務(wù)器 Mysql連接數(shù)設(shè)置 團(tuán)購(gòu)網(wǎng)站 銀行業(yè)務(wù)

在網(wǎng)站設(shè)計(jì)中,ajax技術(shù)的使用已經(jīng)很普遍了,尤其在交互式的網(wǎng)站中,ajax技術(shù)更不可缺少了,幾乎在所有的交互式網(wǎng)站應(yīng)用中,都會(huì)看到ajax的技術(shù),大型網(wǎng)站諸如會(huì)員的注冊(cè),小型網(wǎng)站諸如無(wú)刷新的分頁(yè)技術(shù),給網(wǎng)站瀏覽者更好的用戶(hù)體驗(yàn),在局部網(wǎng)站設(shè)計(jì)中,如果瀏覽某一部分出錯(cuò),而不用去重新刷新整個(gè)網(wǎng)頁(yè),應(yīng)用最廣的部分則是會(huì)員注冊(cè)的無(wú)刷新驗(yàn)證等,無(wú)刷新的分頁(yè),無(wú)刷新的查看更多,無(wú)刷新的查詢(xún)數(shù)據(jù)庫(kù)中內(nèi)容是否存在等等。

下面是ajax的用戶(hù)注冊(cè)模塊,這個(gè)ajax注冊(cè)模塊很實(shí)用,大家只要根據(jù)自己的需要在擴(kuò)展下就可以了,check.php這個(gè)文件是查詢(xún)的數(shù)據(jù)的文件,把里面查詢(xún)的內(nèi)容改成自己的就可以了,應(yīng)該很容易懂的,有需要的可以進(jìn)行下載驗(yàn)證。

check.php

?php
header("Content-Type:text/html;charset=gb2312");
@mysql_connect('localhost','root','ebaeba') or die("數(shù)據(jù)庫(kù)服務(wù)器連接失敗");
@mysql_select_db("test") or die("數(shù)據(jù)庫(kù)不存在或不可用");



$uname = $_GET['userName'];
//下面進(jìn)行數(shù)據(jù)庫(kù)查詢(xún)  查找是不是有這一個(gè)用戶(hù)
//如果沒(méi)有查找到這個(gè)用戶(hù)名



$sql="select * from t1 where name='".$uname."'";
$query=mysql_query($sql);
$row=mysql_fetch_object($query);

if(strlen($uname)6||strlen($uname)>20)
{
 $msg="用戶(hù)名必須是6至20個(gè)字符.";
}
else
{
 
 if($row==false)
 {
  $msg="該用戶(hù)名有效,可以使用!";
 }
 else
 {
  $msg="對(duì)不起,此用戶(hù)名已經(jīng)存在,請(qǐng)更換用戶(hù)名注冊(cè)!";
 }
}
echo $msg ;
?>

reg.php

%@page language="java" contentType="text/html;charset=gb2312"%>
! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"
"http://www.w3.org/TR/REC-html140/strict.dtd">
html>
head>
meta http-equiv="Content-Type" content="text/html; charset=gb2312">
title>AJAX用戶(hù)注冊(cè)演示程序/title>
script language="javascript" type="text/javascript">
!--
//創(chuàng)建函數(shù)
function createXMLHTTP() 
{
 var request;
 var browser = navigator.appName;
 //使用IE,則使用XMLHttp對(duì)象
 if(browser == "Microsoft Internet Explorer") 
 {
 var arrVersions = ["Microsoft.XMLHttp", "MSXML2.XMLHttp.4.0",
  "MSXML2.XMLHttp.3.0", "MSXML2.XMLHttp","MSXML2.XMLHttp.5.0"];
 for (var i=0; i  arrVersions.length; i++) 
 {
  try 
  {
 //從中找到一個(gè)支持的版本并建立XMLHttp對(duì)象
  request = new ActiveXObject(arrVersions[i]); 
  return request;
  } 
  catch (exception)
  {
  //忽略,繼續(xù)
  }
 }
 }
 else
 {
 //否則返回一個(gè)XMLHttpRequest對(duì)象
 request = new XMLHttpRequest(); 
 if(request.overrideMimeType)
 {
    request.overrideMimeType('text/xml');
   }
 return request;
 } 
}
//全局XMLHTTP對(duì)象實(shí)例變量
var http = createXMLHTTP();
//發(fā)送請(qǐng)求
function chkUser()
{
 var url = "check.php"; //請(qǐng)求"CheckUserName" ServLet
 var name = document.getElementById("userName").value; 
 url += ("?userName="+escape(name)+"oprate=chkUser");
 http.open("GET",url,true);
 http.onreadystatechange = ProcessHttpResponse;
 http.send(null);
 return ;
}
//處理響應(yīng)
function ProcessHttpResponse()
{
 if(http.readyState == 4)
 {
 if(http.status == 200)
 {
   var xmlDocument = http.responseXML;
   if(http.responseText!="該用戶(hù)名有效,可以使用!")
  {
 //返回的信息動(dòng)態(tài)顯示
    document.getElementById("showStr").style.display = "";
    document.getElementById("userName").style.background= "#FF0000";
    document.getElementById("showStr").innerText = http.responseText;
   }
  else
  {
    document.getElementById("userName").style.background= "#FFFFFF";
    document.getElementById("showStr").style.display = "";
  document.getElementById("showStr").innerText = http.responseText;
   }
 }
 else
 {
    alert("你所請(qǐng)求的頁(yè)面發(fā)生異常,可能會(huì)影響你瀏覽該頁(yè)的信息!");
    alert(http.status);
 }
 }
}
//檢驗(yàn)輸入密碼
function chkpassword()
{
 var m=document.form1;
 if(m.password.value.length>20 || m.password.value.length6 )
 {
 document.getElementById("passwordStr").style.display = "";
  document.getElementById("password").style.background= "#FF0000";
  document.getElementById("passwordStr").innerText = "對(duì)不起,密碼必須為英文字母、數(shù)字或下劃線,長(zhǎng)度為6~20!";
 }
 else
 {
  document.getElementById("password").style.background= "#FFFFFF";
  document.getElementById("passwordStr").style.display = "none";
 }
}
//驗(yàn)證兩次密碼是否一致
function chkconfirmPassword()
{
 var m=document.form1;
  if (m.password.value != m.confirmPassword.value)
  {
   document.getElementById("confirmPasswordStr").style.display = "";
   document.getElementById("confirmPassword").style.background= "#FF0000";
   document.getElementById("confirmPasswordStr").innerText = "對(duì)不起,密碼與重復(fù)密碼不一致!";
  }
  else
  {
   document.getElementById("confirmPassword").style.background= "#FFFFFF";
   document.getElementById("confirmPasswordStr").style.display = "none";
  }
} 
//驗(yàn)證Email是否有效
function chkEmail()
{
 var m=document.form1;
 var email = m.email.value; 
 //正則表達(dá)式
  var regex = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/; 
  var flag = regex.test(email);   
  if(!flag) 
  {
  document.getElementById("emailStr").style.display = "";
   document.getElementById("email").style.background= "#FF0000";
   document.getElementById("emailStr").innerText = "對(duì)不起,郵箱地址無(wú)效!"; 
  } 
  else 
  { 
  document.getElementById("email").style.background= "#FFFFFF";
   document.getElementById("emailStr").style.display = "none"; 
  }
 
}
//提交檢查函數(shù) 
function SubmitCheck()
{
 var m=document.form1; 
 if(m.userName.value.length==0)
 {
  alert("對(duì)不起,用戶(hù)名必須為英文字母、數(shù)字或下劃線,長(zhǎng)度為5~20。");
  m.userName.focus();
  return false;
 }
 if(m.password.value.length==0)
 {
  alert("對(duì)不起,密碼必須為英文字母、數(shù)字或下劃線,長(zhǎng)度為5~20。");
  m.password.focus();
  return false;
 }
 if (m.password.value != m.confirmPassword.value)
 {
  alert("對(duì)不起,密碼與重復(fù)密碼不一致!");
  m.confirmPassword.focus();
  return false;
 } 
 if(m.email.value.length==0)
 {
  alert("對(duì)不起,郵箱地址不能為空?。?);
  m.email.focus();
  return false; 
 }
 m.submit();
}
//--> 
/script>
body >
form name="form1" method="post" action="register.php">
h3 align="center">Ajax用戶(hù)注冊(cè)程序/h3>
table align="center" width="500" border="1" >
 tr>
 td>font color="red">*/font>/td>
 td width="100">用戶(hù)帳號(hào):/td>
 td>input type="text" name="userName" maxlength="20" style="background=#FFFFFF" onBlur="chkUser()">/td>
 td>div id="showStr" style="background-color:#FF9900;display:none">/div>/td>
 /tr>
 tr>
 td>font color="red">*/font>/td>
 td>用戶(hù)密碼:/td>
 td align="left">input type="password" name="password" maxlength="22" style="background=#FFFFFF" onBlur="chkpassword()"/> /td>
 td>div id="passwordStr" style="background-color:#FF9900;display:none">/div>/td>
 /tr>
 tr>
 td>font color="red">*/font>/td>
 td>確認(rèn)密碼:/td>
 td>input type="password" name="confirmPassword" maxlength="20" style="background=#FFFFFF" onBlur="chkconfirmPassword()"/>/td>
 td>div id="confirmPasswordStr" style="background-color:#FF9900;display:none">/div>/td>
 /tr>
 tr>
 td>font color="red">*/font>/td>
 td>Email:/td>
 td>input type="text" name="email" maxlength="100" style="background=#FFFFFF" onBlur="chkEmail()">/td>
 td>div id="emailStr" style="background-color:#FF9900;display:none">/div>/td>
 /tr>
/table>
div align="center"> 
 
  input type="button" name="ok" value=" 確定 " onClick="SubmitCheck()">
  input type="reset" name="reset" value=" 取消 ">
 /form>
/div>
/body>
/html>

源碼下載:ajax用戶(hù)注冊(cè)模塊

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

您可能感興趣的文章:
  • php+ajax注冊(cè)實(shí)時(shí)驗(yàn)證功能
  • 使用struts2+Ajax+jquery驗(yàn)證用戶(hù)名是否已被注冊(cè)
  • jquery ajax 檢測(cè)用戶(hù)注冊(cè)時(shí)用戶(hù)名是否存在
  • PHP+Ajax異步通訊實(shí)現(xiàn)用戶(hù)名郵箱驗(yàn)證是否已注冊(cè)( 2種方法實(shí)現(xiàn))
  • JQuery運(yùn)用ajax注冊(cè)用戶(hù)實(shí)例(后臺(tái)asp.net)
  • Asp.net下利用Jquery Ajax實(shí)現(xiàn)用戶(hù)注冊(cè)檢測(cè)(驗(yàn)證用戶(hù)名是否存)
  • PHP+AJAX實(shí)現(xiàn)無(wú)刷新注冊(cè)(帶用戶(hù)名實(shí)時(shí)檢測(cè))
  • PHP+Ajax檢測(cè)用戶(hù)名或郵件注冊(cè)時(shí)是否已經(jīng)存在實(shí)例教程
  • asp ajax注冊(cè)驗(yàn)證之 防止用戶(hù)名輸入空格
  • ajax對(duì)注冊(cè)名進(jìn)行驗(yàn)證檢測(cè)是否存在于數(shù)據(jù)庫(kù)中

標(biāo)簽:大理 廣元 江蘇 衢州 萍鄉(xiāng) 蚌埠 棗莊 衡水

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《非常實(shí)用的ajax用戶(hù)注冊(cè)模塊》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢(xún)

    • 400-1100-266