How does AJAX implement the refreshing login function?

Source: Internet
Author: User
To learn how to use ajax to implement the "loose logon" function, the logon window is displayed when you click the "logon" button. enter the correct username and password and click "logon". The logon window is closed and the status is changed to the current username. this article mainly introduces how AJAX can implement the function of refreshing new logon. For more information, see

The logon window is displayed when you click the "log on" button. enter the correct user name and password and click "log on". The logon window is closed and the current user name is in the status.

Step 1:

First, the control in jquery-ui is used in the pop-up window. The first step is to learn how to use it.

Open the development-bundle-> demos under jquery-UI, find index.html, select model dialog under dialog, right-click the source code, observe how to use the control, and find a key code: $ ("# dialog-modal "). dialog ({height: 140, modal: true}); this is used for display. open the source code in the model message and find the key code for disabling it: $ (this ). dialog ('close'); with these two statements of code, you can control the display and close of the window and proceed to the next step. copy the css folder of the jquery-ui development kit to the project.

Step 2:

Here, we will first post the code of the general processing program for processing AJAX requests. Although this code is used for actual writing, it is not possible to list it in detail here. For ease of understanding, first, paste the general processing code:

1. isLogin. ashx is used to determine whether a user is logged on. The user name is returned for logon. note that to use session in a general processing program, you must introduce the using System. web. sessionState and the IRequiresSessionState interface must be implemented

Using System; using System. Collections. Generic; using System. Linq; using System. Web; using System. Web. SessionState; namespace AJAX refreshing new login. AJAX {////// Summary of IsLogin ///Public class IsLogin: IHttpHandler, IRequiresSessionState {public void ProcessRequest (HttpContext context) {context. Response. ContentType = "text/plain"; if (context. Session ["userName"]! = Null) {string userName = context. session ["userName"]. toString (); context. response. write ("yes |" + userName);} else {context. response. write ("no") ;}} public bool IsReusable {get {return false ;}}}}

2. CheckLogin. ashx is used to check whether the user entered the username and password match. If yes, yes is returned. If no is returned, the database is not connected for convenience.

Using System; using System. Collections. Generic; using System. Linq; using System. Web; using System. Web. SessionState; namespace AJAX refreshing new login. AJAX {////// Summary of CheckLogin ///Public class CheckLogin: IHttpHandler, IRequiresSessionState {public void ProcessRequest (HttpContext context) {context. response. contentType = "text/plain"; string userName = context. request ["userName"]; string password = context. request ["password"]; if (userName = "admin" & password = "admin") {context. session ["userName"] = "admin"; context. response. write ("OK");} else {context. response. write ("no") ;}} public bool IsReusable {get {return false ;}}}}

3. LoginOut. ashx, used to control user logout and set the session to null.

Using System; using System. Collections. Generic; using System. Linq; using System. Web; using System. Web. SessionState; namespace AJAX refreshing new login. AJAX {////// LoginOut summary ///Public class LoginOut: IHttpHandler, IRequiresSessionState {public void ProcessRequest (HttpContext context) {context. response. contentType = "text/plain"; context. session ["userName"] = null;} public bool IsReusable {get {return false ;}}}}

The general processing program ends. the code of the main interface is shown below:

  
   
  

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.