AJAX implements the user registration function

Source: Internet
Author: User
Tags trim
Features:

1. Realize the user registration function;
2. Implementing an existing user name cannot be registered;
3. User name, password non-null authentication;
4. Password confirmation; User Registration Interface register.html

<! DOCTYPE html>  
User Registration General Handler 
register.ashx 
<%@ WebHandler language= "C #" class= "Register"%> using System;
Using System.Web;
Using System.Web.Script.Serialization;
Using Web1;
Using System.Data.SqlClient;

Using System.Data; public class Register:ihttphandler {public void ProcessRequest (HttpContext context) {context. Response.ContentType = "Application/json";//1. Modify the message type//1. Gets the user name and password string user=context. request["Name"].
        Trim (); String Password=context. request["Password"].

                Trim (); 4>>>>> prohibited words, word length limit can also add//2 ". Non-null check if (string. Isnullorwhitespace (user)) {context. Response.Write (New JavaScriptSerializer (). Serialize (New {status= "error", msg= "user name cannot be empty.
            "}));
        Return } if (string. Isnullorwhitespace (password)) {context. Response.Write (New JavaScriptSerializer (). Serialize (New {Status = "error", MSG = "Password cannot be empty.
            " }));
        Return }//3 ". Check for user name presence DaTatable dusers = sqlhelper.executequery ("Select username from t_users where username= @username", New System.Data .
        Sqlclient.sqlparameter ("@UserName", user)); if (dusers.rows.count>1) {context. Response.Write (New JavaScriptSerializer ().
            Serialize (New {status= "error", msg= "User already exists"});
        Return }//4.  Insert Database Sqlhelper.executenonquery ("INSERT into t_users (Username,password) VALUES (@username, @password)",
        New SqlParameter ("@username", user), New SqlParameter ("@password", password)); Context. Response.Write (New JavaScriptSerializer ().
    Serialize (New {status= "OK", msg= "registered successfully"});
        } public bool IsReusable {get {return false; }
    }

}
User Table

Run Results

errors (all letters are missing or wrongly written)



Summary:

Ajax-ajax,ajax,ajax,ajax,ajax, Ajaxajaxajaxajaxajaxajaxajaxajaxajaxajaxajaxajaxajaxajaxajaxajaxajaxajaxajaxajaxajaxajaxajaxajaxajaxajaxajaxajaxajaxajaxa Jaxajaxajaxajaxajaxajaxajaxajaxajaxajaxajaxajaxajaxajaxajaxajaxajaxajaxajaxajaxajaxajaxajaxajaxajaxajaxajaxajaxajaxajaxaj Axajaxajaxajaxajaxajaxajaxajaxajaxajaxajaxajaxajaxajaxajaxajaxajaxajaxajaxajax .....

Related Article

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.