来个异步查询用户名是否存在

来个异步查询用户名是否存在
index.aspx

HTML code 

<script type="text/javascript" language="javascript">
        function validateloginname()
        {
            var loginname=document.getElementById("Text1").value;

            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
            xmlHttp.onreadystatechange=getdata;
            xmlHttp.Open("GET","validate.aspx?loginname="+loginname,true);
            xmlHttp.Send();
        }
        function getdata()
        {
            if(xmlHttp.readystate==4)
            {
                if(xmlHttp.status==200)
                {
                    var text=xmlHttp.responseText;
                    if(text=="1")
                    {
                        document.getElementById("td1").innerHTML="用户名已存在";
                        document.getElementById("Text1").style.borderColor="Black";
                        document.getElementById("Text1").focus();
                         document.getElementById("Text1").value="";
                    }
                    else
                    {
                         document.getElementById("td1").innerHTML="OK";
                         document.getElementById("Text1").style.borderColor="Red";
                    }
                }
            }
        }
    </script>

 <td>
                    <input id="Text1" type="text" runat="server" onblur="validateloginname()" />
                </td>
                <td id="td1">
                   
                </td>




validate.aspx

C# code 

    protected void Page_Load(object sender, EventArgs e)
    {
        string loginname = Request.QueryString["loginname"];

        if (loginname == "mcluzhi")
        {
            Response.Write("1");
        }
        else
        {
            Response.Write("0");
        }
    }
posted @ 2012-01-18 14:10  kangwl  阅读(200)  评论(0编辑  收藏  举报