点击某一超链接调用javascript方法
<a href=“javascript:ajax();”>点击验证</a>
//ajax
<script language="javascript" type="text/javascript">
var request = false;
function ajax()
{
var error = true;
try
{
request = new XMLHttpRequest();
}
catch (trymicrosoft)
{
try
{
request = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (othermicrosoft)
{
try
{
request = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (failed)
{
request = false;
}
}
}
if(!error)
{
alert("ajax error!");
}
request.open("GET","validateEmail.aspx?session="+document.getElementByIdx("txtEmail").value,true);//验证的文本框名称
request.onreadystatechange = updatePage;
request.send(null);
}
function updatePage()
{
if(request.readyState == 4)
{
if(request.responseText=="1")
{
alert("该用户已经注册!");
return false;
}
if(request.responseText=="0")
{
alert("可以注册!");
return false;
}
}
}
</script>
单独一页,别的页调用它:validateEmail.aspx
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["session"] != null)//验证页面传递过来的值
{
string session = Request.QueryString["session"].ToString();
registerBll regb = new registerBll();
DataSet ds = regb.selectMemberxx(session);//数据连接的查询类,以查询用户名
if (ds.Tables[0].Rows.Count > 0)
{
Response.Write("1");
}
else
{
Response.Write("0");
}
}
}