HTML代碼如下:
LoginValidate.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="LoginValidate.aspx.cs" Inherits="LoginValidate" %>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>驗證使用者名稱是否存在</title>
<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()
{
createXMLHttpRequest();
var url= "LoginValidate.ashx?username="+document.getElementById ("username").value;
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=ShowResult;
xmlHttp.send(null);
//document.getElementById("Msg").innerHTML='';
}
//回調方法
function ShowResult()
{
if(xmlHttp.readyState==4)
{
if(xmlHttp.status==200)
{
document.getElementById("Msg").innerHTML=xmlHttp.responseText;
}
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="width: 487px">
<tr>
<td style="width: 70px">
使用者名稱:</td>
<td style="width: 231px"><input id="username" type="text" />
<input id="Button1" type="button" value="button" onclick="CheckUserName();" /></td>
<td id="Msg"></td>
</tr>
<tr>
<td style="width: 70px">
</td>
<td style="width: 231px">
</td>
<td>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>