zoukankan      html  css  js  c++  java
  • 原创Ajax实现无刷新判断用户是否可以注册

    最近项目进入尾期,主要给客户进行一些培训。客户在注册系统时每次会出现在填写完所有的信息后,在点击确定后,如果后台有此用户名,就添加不了,但页面上填写的信息可能就没了,比如密码项一定会清空。这是一个不人性化的地方,看网上好多论坛实现填写用户名后失去焦点后就可判断出是否可以填写.就在项目中添加此功能了~~

    前台apx中加JS

    <!--
    var xmlHttp;
    function createXMLHttpRequest(){
        
    if(window.ActiveXObject){
            xmlHttp 
    = new ActiveXObject("Microsoft.XMLHTTP");
        }

        
    else if(window.XMLHttpRequest){
            xmlHttp 
    = new XMLHttpRequest();
        }

    }


      
    function checkUserName(){
         
    var UserName = document.getElementById('tbxManagerName');
         
    if (UserName.value == "")
                
    return;
        createXMLHttpRequest();
        
    var url = "check_user.aspx?UserName=" +UserName.value;
        xmlHttp.open(
    "GET",url,true);
        xmlHttp.onreadystatechange 
    = handleStateChange;
        xmlHttp.send(
    null);
    }


    function handleStateChange(){
        
    if(xmlHttp.readyState == 4){
            
    if(xmlHttp.status == 200){
                
    var isValid = xmlHttp.responseText;
                
    var checkResult = document.getElementById("checkResult");
                checkResult.innerHTML 
    = (isValid == "true"? "<IMG src= 'http://www.cnblogs.com/images/check_right.gif' align = 'absmiddle'>&nbsp;&nbsp;恭喜,此用户可以注册!" : "<IMG src= 'http://www.cnblogs.com/images/check_error.gif' align = 'absmiddle'>&nbsp;&nbsp;此用户名已存在,请选择基他用户名!";         
            }

        }

    }

    后台check_user.aspx.cs
    private void Page_Load(object sender, System.EventArgs e)
            
    {
                
    string UserName = Request.QueryString["UserName"];
            
                
    // validate
                bool isValid = false;
                
    int count = 0;
                count 
    = (new BRL.Sys.ManagerBR()).GetResultByCondition(ManagerDS.MANAGER_TABLE,"Manager_LoginName = '"+UserName+"'");
                
    if(count == 0)
                    isValid 
    = true;        
                
                Response.Clear();
                Response.Write(isValid 
    ? "true" : "false");
                Response.End();
            }

    运行效果如下:
    可以注册:
    check_right.jpg
    不可以注册:
    123.jpg
  • 相关阅读:
    安装图形化界面
    cemtos安装python
    traceback说明
    python常用魔法函数
    python上传文件接口
    文件上传接口
    MongoDB安装与使用
    解决macOS系统向有跳板机的服务器传文件
    mac终端命令sftp
    linux下mysql服务安装
  • 原文地址:https://www.cnblogs.com/conquer/p/1138085.html
Copyright © 2011-2022 走看看