日期:2014-05-17 浏览次数:20470 次
<script type="text/javascript" src="Scripts/AjaxCommon.js"></script> <script type="text/javascript" > //创建Ajax异步对象,验证重复账户 function CheckRegistID(email) { var xhr = false; xhr = CreatXmlHttp(); xhr.open("Get", "Hendler/CheckRegisterID.ashx?email="+email+"&st"+new Date(), true);//注意加上随机函数更新缓存 xhr.onReadyStateChange = function () { if (xhr.readyState == 4 && xhr.status == 200) { if (xhr.ResponseText == "yes") { gel("lab_registMsg").innerHTML= "欢迎该账户注册"; } else { gel("lab_registMsg").innerHTML = "该账户已被注册!"; } } } xhr.send(null); }
<asp:textbox id="txt_RegistID" runat="server" Width="150px" CssClass="InputCss" onblur="CheckRegistID(this.value)" AutoPostBack="True"></asp:textbox>
public void ProcessRequest (HttpContext context) { string email = ""; SqlDataReader email_dr = null;//创建一个查询段 context.Response.ContentType = "text/plain"; email = context.Request["email"]; BLL.User CheckEmail = new BLL.User();//实例化查询对象 email_dr = CheckEmail.CheckRegistID(email); if (email_dr.Read()) { context.Response.Write("yes"); } else { context.Response.Write("no"); } }
<!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 runat="server"> <title>无标题页</title> <script src="jquery-1.4.2.min.js" type="text/javascript"></script> <script type="text/javascript"> function add() { $.post("action.aspx",{Action:"post",str:$("#TextBox1").val()}, function(value,textStatus) { alert(value); } ); } </script> </head> <body> <form id="form1" runat="server"> <div> <asp:TextBox ID="TextBox1" runat="server" onblur="add()"></asp:TextBox> </div> </form>