JS部分:
<script type="text/javascript" >
//验证用户名是否正确
function JudgeUserName() {
var username = $("#userName").val()
$.ajax({
type: "Post",
url: ''RegisterUserNameVerity.ashx/ProcessRequest?username=''+username,
success: function (result) {
if (username == "") {
alert("用户名不能为空!");
document.getElementById("userName").focus();
document.getElementById("userName").selected;
} else {
if (result == "True") {
alert("已存在,请您重新选择一个用户名!")
document.getElementById("userName").focus;
document.getElementById("userName").select();
}
}
},
});
}
</script>
Html部分:
<input type="text" οnblur="JudgeUserName()" />
一般处理程序部分:
public void ProcessRequest(HttpContext context)
{
//获取从前台传过来
string userName = context.Server.UrlDecode(context.Request.QueryString["username"]);
//声明查询用户名是否存在的对象
userBLL verifyusernamebll = new userBLL();
//通过其他的函数来判断
bool flag=verifyusernamebll.Exists(userName);
if (flag==true)
{
context.Response.Write(true);
}
else
{
context.Response.Write(false);
}
}