Ajax mailbox, user name uniqueness verification instance code, ajax instance

Source: Internet
Author: User

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!

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

11.11 Big Sale for Cloud

Get Unbeatable Offers with up to 90% Off,Oct.24-Nov.13 (UTC+8)

Get It Now >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.