这次给大家带来用Ajax如何验证邮箱、用户名的唯一性,用Ajax验证邮箱、用户名唯一性的注意事项有哪些,下面就是实战案例,一起来看一下。
废话不多说了,直接给大家贴代码了,具体代码如下所示:
<script type="text/javascript">
$(function () {
$("#txtEmail").blur(function () {
$.ajax({
type: "post",
url: "reg.ashx?email=" + $.trim($("#txtEmail").val()) + "&d=" + (+new Date()),
success: function (data) {
var vCount = parseInt(data);
if (vCount == 0) {
alert("邮箱可以使用");
}
else {
alert("邮箱已经被占用");
}
}
});
});
$("#checkpwd").blur(function () {
return CheckPwd();
});
});
function CheckPwd()
{
var bCheck = true;
if ($.trim($("#pwd").val()) != $.trim($("#checkpwd").val()))
{
alert("两次密码输入不一致");
bCheck = false;
}
return bCheck;
}
</script>reg.ashx代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace WebT1.Ti.html2
{
/// <summary>
/// reg 的摘要说明
/// </summary>
public class reg : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
if (context.Request["email"] != null)
{
string strEmail = context.Request["email"];
List<UserModel> lstUser = DataService.GetUserList();
var v = lstUser.Where(p => p.Email == strEmail);
int iCount = 0;
if (v.Count() > 0)
{
iCount = 1;
}
context.Response.ContentType = "text/plain";
context.Response.Write(iCount.ToString());
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
public class DataService
{
/// <summary>
/// 模拟已注册用户数据
/// </summary>
public static List<UserModel> GetUserList()
{
var list = new List<UserModel>();
list.Add(new UserModel() { Email = "t1@demo.com" });
list.Add(new UserModel() { Email = "t2@demo.com" });
list.Add(new UserModel() { Email = "t3@demo.com" });
list.Add(new UserModel() { Email = "t4@demo.com" });
list.Add(new UserModel() { Email = "t5@demo.com" });
return list;
}
}
public class UserModel
{
public string Email { get; set; }
}
}
相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!
推荐阅读:
去日租程序是一款具有强大的功能的基于.NET+SQL2000+AJAX构架的房屋出租管理系统。 日租网站管理系统,采用ASP.NET2.0语言开发,它集成租房模块、文章模块、订单模块、邮箱短信模块、用户模板、SEO优化模块、房间模块、支付模块等多项强大功能。系统有多年经验的高级工程师采用三层架构开发,页面代码全部采用DIV+CSS,完全符合SEO标准,有利于搜索引擎关键排名优化。日租网站
0
以上就是用Ajax如何验证邮箱、用户名的唯一性的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号