濮阳杆衣贸易有限公司

主頁(yè) > 知識(shí)庫(kù) > AJAX實(shí)現(xiàn)無(wú)刷新檢測(cè)用戶(hù)名功能

AJAX實(shí)現(xiàn)無(wú)刷新檢測(cè)用戶(hù)名功能

熱門(mén)標(biāo)簽:中國(guó)地圖標(biāo)注不明確情況介紹表 怎樣在地圖標(biāo)注文字 東平縣地圖標(biāo)注app 立陶宛地圖標(biāo)注 河間市地圖標(biāo)注app 大眾點(diǎn)評(píng)400電話怎么申請(qǐng) 地圖標(biāo)注推銷(xiāo)坑人 電銷(xiāo)機(jī)器人 長(zhǎng)春 上海企業(yè)外呼系統(tǒng)價(jià)錢(qián)

先來(lái)看看原理圖

register.php

!DOCTYPE html>
html>
 head>
  meta charset="utf-8" />
  title>ajax無(wú)刷新檢測(cè)/title>
  style type="text/css">
   body{margin:0;padding:0;}.content{width:800px;margin:0 auto;}ul,li{list-style: none;margin:0;padding:0;}
   tr{width:200px;}td{width:80px;padding:5px 0;}td input,textarea{border: 1px solid #79ABFE;} 
  /style>
 /head>
 body>
  div class="content">
   script>
    myXmlHttpRequest.ContentType=("text/xml;charset=UTF-8");
    //創(chuàng)建ajax引擎(1號(hào)線)
    function getXmlHttpObject(){   
     var xmlHttpRequest;
     //不同瀏覽器獲取對(duì)象xmlHttpRequest方法不一樣
     if(window.ActiveXObject){
      xmlHttpRequest=new ActiveXObject("Microsoft.XMLHTTP");
     }else{
      xmlHttpRequest=new XMLHttpRequest();
     }
     return xmlHttpRequest;
    }
    //驗(yàn)證用戶(hù)名是否存在
    var myXmlHttpRequest="";//因?yàn)閏huli也用到了,所以要定義為全局變量 
    //創(chuàng)建方法(2號(hào)線 http請(qǐng)求)
    function checkName(){
     //創(chuàng)建對(duì)象 
     myXmlHttpRequest=getXmlHttpObject();
     //判斷是否創(chuàng)建ok
     if(myXmlHttpRequest){
      //通過(guò)myXmlHttpRequest對(duì)象發(fā)送請(qǐng)求到服務(wù)器的某個(gè)頁(yè)面 
      var url="./registerPro1.php";
      //要發(fā)送的數(shù)據(jù)
      var data="username="+$('username').value;
      //打開(kāi)請(qǐng)求
      myXmlHttpRequest.open("post",url,true);//ture表示使用異步機(jī)制
      //POST方法
      myXmlHttpRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
      //指定回調(diào)函數(shù),chuli是函數(shù)名(registerPro里的數(shù)據(jù)返回給chuli函數(shù))
      myXmlHttpRequest.onreadystatechange=chuli;
      //開(kāi)始發(fā)送數(shù)據(jù),如果是get請(qǐng)求則填入null即可,如果是post請(qǐng)求則填入實(shí)際的數(shù)據(jù)
      myXmlHttpRequest.send(data);
     }
    }
    //回調(diào)函數(shù)(4號(hào)線)
    function chuli(){
     //取出從registerPro.php頁(yè)面返回的數(shù)據(jù)(4表示完成,200表示成功)
     if(myXmlHttpRequest.readyState==4){
      if(myXmlHttpRequest.status==200){
      //①、取出值,根據(jù)返回信息的格式定 text(html)
      //$('result').value=myXmlHttpRequest.responseText;
      //②、取出xml格式數(shù)據(jù)(解析)
      //獲取mes節(jié)點(diǎn)、這里的mes返回的是節(jié)點(diǎn)列表(不知道有幾個(gè)mes)
      //var mes=myXmlHttpRequest.responseXML.getElementsByTagName("mes");
      //取出mes節(jié)點(diǎn)值
      //mes[0]->表示取出第一個(gè)mes節(jié)點(diǎn)
      //mes[0].childNodes[0]->表示取出mes節(jié)點(diǎn)的第一個(gè)子節(jié)點(diǎn)
      //var mes_val=mes[0].childNodes[0].nodeValue;
      //$("result").value=mes_val; 
      //③、json格式
      //var mes=myXmlHttpRequest.responseText;
      //使用eval函數(shù),將mes字串轉(zhuǎn)為對(duì)象
      //var mes_obj=eval("("+mes+")");
      //$('result').value=mes_obj.res;
      //③+、json格式擴(kuò)展
      var mes=myXmlHttpRequest.responseText;
      var mes_obj=eval("("+mes+")");
      $('result').value=mes_obj[0].res;
      }
     }
    }  
    //封裝一個(gè)函數(shù),通過(guò)id號(hào)獲取對(duì)象
    function $(id){
     return document.getElementById(id);
    } 
   /script>
   br/>
   strong style="color:red">發(fā)表留言/strong>
   form action="#" method="POST" name="frm">
   table cellpadding="0" cellspacing="0" >
    tr>
     td >留言標(biāo)題:/td>
     td>input type="text" name="title" autocomplete="off"/>/td>
    /tr>
    tr>
     td>網(wǎng)名:/td>
     td>
      input id="username" onkeyup="checkName();" type="text" name="username" autocomplete="off"/>
      td>input id="result" type="text" style="width:110px;font-size: 12px;border-width:0;" >/td> 
     /td>
    /tr>
    tr>
     td>留言?xún)?nèi)容:/td>
     td>textarea name="content" cols="26" rows="5" autocomplete="off"/ onclick="showNotice(this)">/textarea>/td>
    /tr>
    tr>
     td>/td>
     td>input class="btn" type="submit" name="submit" value="提交"/>/td>
    /tr>
   /table>
   /form>
  /div> 
 /body>
/html>

registerPro1.php

?php
 //將數(shù)據(jù)(text格式,xml格式,json格式)返回到ajax引擎(3號(hào)線 http響應(yīng) )
 
 //header("Content-Type: text/xml; charset=utf-8"); //告訴瀏覽器,返回的是xml格式
 header("Content-Type: text/html; charset=utf-8"); //告訴瀏覽器,返回的是text/json格式
 $username = $_POST["username"];
 //①
// if($username=="abc"){
//  echo '網(wǎng)名不可用';
// }else{
//  echo '網(wǎng)名可用';
// }
 //②
// $info="";
// if($username=="abc"){
//  $info.="res>mes>網(wǎng)名不可用/mes>/res>";
// }else{
//  $info.="res>mes>網(wǎng)名可用/mes>/res>";
// }
// echo $info;
 //③
// $info="";
// if($username=="abc"){
//  //這里的$info返回的是一個(gè)字串
//  $info.='{"res":"不可用","id":"123","age":"5"}';
// }else{
//  $info.='{"res":"可用","id":"3","age":"1"}';
// }
// echo $info;
 //③+
 $info="";
 if($username=="abc"){
  //這里的$info返回的是一個(gè)字串
  $info.='[{"res":"不可用","id":"123","age":"5"},{"res":"abc不可用","id":"3","age":"0"}]';
 }else{
  $info.='[{"res":"可用","id":"1","age":"15"},{"res":"可用","id":"83","age":"9"}]';
 }
 echo $info;
?>

效果圖:

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

您可能感興趣的文章:
  • 利用Ajax檢測(cè)用戶(hù)名是否被占用的完整實(shí)例
  • JQuery Ajax如何實(shí)現(xiàn)注冊(cè)檢測(cè)用戶(hù)名
  • PHP+Ajax實(shí)現(xiàn)的檢測(cè)用戶(hù)名功能簡(jiǎn)單示例
  • AJAX應(yīng)用實(shí)例之檢測(cè)用戶(hù)名是否唯一(實(shí)例代碼)
  • jQuery+Ajax實(shí)現(xiàn)用戶(hù)名重名實(shí)時(shí)檢測(cè)
  • 使用Ajax實(shí)時(shí)檢測(cè)"用戶(hù)名、郵箱等"是否已經(jīng)存在
  • PHP+Ajax檢測(cè)用戶(hù)名或郵件注冊(cè)時(shí)是否已經(jīng)存在實(shí)例教程
  • Asp.net下利用Jquery Ajax實(shí)現(xiàn)用戶(hù)注冊(cè)檢測(cè)(驗(yàn)證用戶(hù)名是否存)
  • jquery ajax 檢測(cè)用戶(hù)注冊(cè)時(shí)用戶(hù)名是否存在
  • PHP+AJAX實(shí)現(xiàn)無(wú)刷新注冊(cè)(帶用戶(hù)名實(shí)時(shí)檢測(cè))
  • PHP+AJAX實(shí)現(xiàn)無(wú)刷新注冊(cè)(帶用戶(hù)名實(shí)時(shí)檢測(cè))
  • ajax 檢測(cè)用戶(hù)名是否被占用
  • AJAX檢測(cè)用戶(hù)名是否存在的方法

標(biāo)簽:玉樹(shù) 遼寧 銅川 內(nèi)江 本溪 四川 營(yíng)口 益陽(yáng)

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《AJAX實(shí)現(xiàn)無(wú)刷新檢測(cè)用戶(hù)名功能》,本文關(guān)鍵詞  AJAX,實(shí)現(xiàn),無(wú),刷新,檢測(cè),;如發(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)文章
  • 下面列出與本文章《AJAX實(shí)現(xiàn)無(wú)刷新檢測(cè)用戶(hù)名功能》相關(guān)的同類(lèi)信息!
  • 本頁(yè)收集關(guān)于AJAX實(shí)現(xiàn)無(wú)刷新檢測(cè)用戶(hù)名功能的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    平邑县| 油尖旺区| 宜川县| 普陀区| 安丘市| 博罗县| 江门市| 米易县| 正阳县| 杭州市| 军事| 青海省| 汕尾市| 河间市| 九江县| 高雄市| 诸暨市| 望谟县| 嫩江县| 江北区| 五常市| 汶上县| 灌阳县| 襄汾县| 长沙县| 九龙坡区| 商洛市| 翁牛特旗| 龙口市| 修水县| 大田县| 桐庐县| 阳曲县| 榕江县| 上饶县| 永年县| 沂水县| 晋宁县| 大厂| 图木舒克市| 南召县|