How does AJAX implement the refreshing login function and ajax implements the refreshing login function?

Source: Internet
Author: User

How does AJAX implement the refreshing login function and ajax implements the refreshing login function?

Recently, I learned how to implement a new account without refreshing. The general effect is as follows (the interface is ugly, please ignore it yourself ....):

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 decompressed jquery-UIdevelopment-bundle->demosFind 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 to close: $ (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 does not require any new logon. AJAX {/// <summary> /// Brief description of IsLogin /// </summary> 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 does not require any new logon. AJAX {/// <summary> /// summary of CheckLogin /// </summary> 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 does not require any new logon. AJAX {/// <summary> /// LoginOut abstract description /// </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:

<% @ Page Language = "C #" AutoEventWireup = "true" CodeBehind = "Login. aspx. cs" Inherits = "AJAX refreshing new Login. Login" %>
<! DOCTYPE html> 

The above section describes how to implement the no-refreshing logon function of AJAX, which is provided by the editor. I hope it will be helpful to you. If you have any questions, please leave a message and the editor will reply to you in a timely manner. Thank you very much for your support for the help House website!

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.