登陆账号是唯一键,怎么用js判断账号已存在?

解决方案 »

  1.   

    没错,正是ajax的用武之地不过,用iframe提交查询也可以实现.
      

  2.   


    <script>
    var xmlHttp1;startRequest('get','yonghu.ashx','uername='+escape(tusername)+'',ShowIt,true);
    //把取到的名字传到yonghu.ashx文件,然后接收值根据这个值到数据库查询,查到了就返回一个OK
           function createXMLRequest()
           {
               if(window.ActiveXObject)
               {
                  xmlHttp1=new ActiveXObject("Microsoft.XMLHTTP");
               }
               else if(window.XMLHttpRequest)
               {
                  xmlHttp1=new XMLHttpRequest();
               }
               else
               {
                  alert("不能创建XMLHttpRequest");
               }
           }
           function startRequest(method,url,pars,callbackfun,cache)
           { 
               
              if(typeof callbackfun != 'function'){
                alert('The CallBackFun is not a function!');
              }
              if(cache){
                pars += "&tmp="+Math.random();
              }
              createXMLRequest();
              xmlHttp1.onreadystatechange = function(){
                  if(xmlHttp1.readyState==4)
                  {
                     if(xmlHttp1.status==200)
                     {
                         callbackfun(xmlHttp1);
                         xmlHttp1.abort();
                     }
                     else
                     {
                        xmlHttp1.abort();
                        alert("请求出错!");
                     }
                  }
              }   
             
              xmlHttp1.open(method,url+'?'+pars,true);
              xmlHttp1.send(null);
           }
         function ShowIt(req)
    {
      
       if(req.responseText=="ok")
       {
         alert('用户名已存在');
       }
       
    }
    </script>
      

  3.   

    ajax验证用户唯一
    http://www.cnblogs.com/ywqu/archive/2009/06/03/1495680.html
      

  4.   

    http://blog.csdn.net/nextuntil/archive/2010/06/07/5654201.aspx上次写的一个jquery+ajax即时验证用户名是否已经存在的例子勒LZ可以参考下
      

  5.   

    ajax异步获取数据,查询用户数据  
    <script type="text/javascript">  
      var xmlHttp;  
      function createXMLHttpRequest()  
      {  
      if(window.ActiveXObject)  
      {  
      xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");  
      }  
      else if(window.XMLHttpRequest)  
      {  
      xmlHttp = new XMLHttpRequest();  
      }  
      }  
      function CheckUserName()  
      {  
      var us=document.getElementById("txtname").value;  
      if(us!="")  
      {  
      createXMLHttpRequest();  
      var url= "RegistValidate.ashx?username="+escape(document.getElementById("txtname").value);  
      xmlHttp.open("GET",url,true);  
      xmlHttp.onreadystatechange=ShowResult;  
      xmlHttp.send(null);  
      }  
      }  
      function ShowResult()  
      {  
      if(xmlHttp.readyState==4)  
      {  
      if(xmlHttp.status==200)  
      {  
      var s;  
      s=xmlHttp.responseText;  
      alert(s);  
      }  
      }  
      }  
    </script>