1. default.aspx
function test(a)
{
var xmlhttp;
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
alert(xmlhttp.responseText);
document.getElementById("txtStuName").innerHTML=xmlhttp.responseText;
document.getElementById("txtCellNo").innerHTML=xmlhttp.responseText;
}
}
var url = "check.aspx?UserName=" +a;
xmlhttp.open("GET",url,true);
xmlhttp.send();
}
2. check.aspx
protected void Page_Load(object sender, EventArgs e)
{
conn.Open();
string s = Request.QueryString.Get("UserName").ToString();
if (!string.IsNullOrEmpty(s))
{
string str = "select * from StuInfo where StuName = '" + s + "'";
cmd = new SqlCommand(str, conn);
string status = null;
SqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
status = "duplicate uaername";
}
else
{
status = "username available";
}
Response.Write(status);
conn.Close();
}
else
{
string status = "Name should not be null";
Response.Write(status);
}
}