<%@ page language="c#" contenttype="text/html" responseencoding="gb2312" %>
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title>jquery 验证用户名(ajax验证用户名是否存在)</title>
<script type="text/网页特效" src="css教程/jquery-1.3.2.网页特效"></script>
<script type="text/javascript">
function judgeusername()
{
$.ajax({
type:"get",
url:"www.111cn.net.asp教程x",
datatype:"html",
data:"username="+$("#txtname").val(),
beforesend:function(xmlhttprequest)
{
$("#showresult").text("正在查询");
//pause(this,100000);
},
success:function(msg)
{
$("#showresult").html(msg);
$("#showresult").css("color","red");
},
complete:function(xmlhttprequest,textstatus)
{
//隐藏正在查询图片
},
error:function()
{
//错误处理
}
});
}</script>
</head><body>
<div>
<input id="txtname" type="text" /><input type="button" value="查看用户名是否存在" id="btn" onclick="judgeusername();" />
<div id="showresult" style="float:left"></div>
</div>
</body>
</html>
<%
protected void page_load(object sender, eventargs e)
{
string username = request.querystring["username"].tostring ();
if (username == "james hao")
{
response.write ("用户名已经存在!");
}
else
{
response.write ("您可以使用此用户名!");
}
}
/*
异步刷新实现方式有多种,也可以借助js的多种框架,下面是使用jquery框架实现的ajax 验证用户名是否存在
*/
%>