html代码:
- <head>
- <script type="text/javascript">
- var xmlHttp;
- function createXMLHttpRequest()
- {
- if(window.XMLHttpRequest)
- {
- xmlHttp = new XMLHttpRequest();//mozilla浏览器
- }
- else if(window.ActiveXObject)
- {
- try
- {
- xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
- }
- catch(e){}
- try
- {
- xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
- }
- catch(e){}
- if (!xmlHttp)
- {
- alert("不能创建xmlHttp对象实例!");
- }
- }
- }
- function CheckName(userName)
- {
- createXMLHttpRequest();
- var url="Dispost.aspx?Name="+userName;
- xmlHttp.onreadystatechange = CheckUserName;
- xmlHttp.open("GET",url,true);
- xmlHttp.send(null);
- }
- function CheckUserName()
- {
- if(xmlHttp.readyState==4)
- {
- if(xmlHttp.status==200)
- {
- if(xmlHttp.responseText=="true")
- {
- document.getElementById('check').innerText="可以注册";
- }
- else
- {
- document.getElementById('check').innerText="不可以注册";
- }
- }
- }
- }
- </script>
- </head>
- <body>
- 用户名:<input id="userName" type="text" οnkeyup="CheckName(document.getElementById('userName').value);">
- <div id="check"></div>
- </body>
- Dispost.aspx后台代码:
- protected void Page_Load(object sender, EventArgs e)
- {
- User user=new User();
- if(user.checkName(Resquest.QueryString["Name"].ToString()))
- {
- Response.Write("false");
- Response.End();
- }
- else
- {
- Response.Write("true");
- Response.End();
- }
- }