HTML代碼如下
LoginValidate
<%@ Page Language=
<html xmlns=
<head runat=
<title>驗證用戶名是否存在</title>
<script type=
var xmlHttp;
function createXMLHttpRequest()
{
if(window
{
xmlHttp = new ActiveXObject(
}
else if(window
{
xmlHttp = new XMLHttpRequest()
}
}
//處理方法
function CheckUserName()
{
createXMLHttpRequest()
var url=
xmlHttp
xmlHttp
xmlHttp
//document
}
//回調方法
function ShowResult()
{
if(xmlHttp
{
if(xmlHttp
{
document
}
}
}
</script>
</head>
<body>
<form id=
<div>
<table >
<tr>
<td >
用戶名
<td ><input id=
<input id=
<td id=
</tr>
<tr>
<td >
</td>
<td >
</td>
<td>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
服務器端代碼如下
LoginValidate
<%@ WebHandler Language=
using System;
using System
using System
using System
public class LoginValidate : IHttpHandler
{
public void ProcessRequest (HttpContext context)
{
context
string username = context
string strSQL =
if (ReDataSet(strSQL)
{
context
}
else
{
context
}
System
}
//數據庫連接字符串
public static string strCon =
/// <summary>
/// 執行SQL語句
/// </summary>
/// <param name=
/// <returns></returns>
public DataSet ReDataSet(string strSQL)
{
SqlConnection con = new SqlConnection(strCon)
try
{
con
SqlDataAdapter da = new SqlDataAdapter(strSQL
DataSet ds = new DataSet()
da
return ds;
}
catch (Exception ex)
{
throw new Exception(ex
}
finally
{
con
}
}
/// <summary>
/// 不重復調用
/// </summary>
public bool IsReusable
{
get
{
return false;
}
}
}
From:http://tw.wingwit.com/Article/program/net/201311/11585.html