Ajax mailbox, user name uniqueness verification instance code, ajax instance
If you don't talk much about it, paste the Code directly. The specific code is as follows:
<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 ("email can be used") ;}else {alert ("email already occupied ");}}});}); $ ("# checkpwd "). blur (function () {return CheckPwd () ;}); function CheckPwd () {var bCheck = true; if ($. trim ($ ("# pwd "). val ())! = $. Trim ($ ("# checkpwd "). val () {alert ("two passwords are inconsistent"); bCheck = false;} return bCheck ;}</script>
Reg. ashx code:
Using System; using System. collections. generic; using System. linq; using System. web; namespace WebT1.Ti.html 2 {// <summary> // reg abstract description /// </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> // simulate registered user data /// </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 ;}}}
Summary
The above is the example code of Ajax mailbox and user name uniqueness verification introduced by xiaobian. I hope it will be helpful to you. If you have any questions, please leave a message and I will reply to you in a timely manner. Thank you very much for your support for the help House website!