Okay, that’s it for the chatter. Now let’s see how to use jquery to achieve refresh-free login.
First create the html part
The functions included here are: login Verify, click Change Verification Code. There is nothing to say about this.
The following is the jquery part
-----------Don’t forget to quote this link, otherwise jquery will not work
This is the approximate core code. When the user clicks the login button, the login event is triggered, and jquery is used to log in to Login.ashx When making a request, in Login.ashx, it just verifies whether the username and password match and whether the verification code is correct. Login.ashx is written in C# language. If you are learning another language, just change the address to another one.
img.ashx is a program that generates verification codes. Every time you click on an image, img.ashx will be revisited, so the image is changed. When the image is generated, a session will be generated to store the verification code. In Login.ashx, Just determine whether the value entered by the user and the value of the session are the same. Here I only show the main source code.
context.Response.ContentType = "text/plain";
string username = context.Request.Form["username"];
string password = context.Request.Form["password"];
string cord = context.Request.Form["cord"] ;
if (context.Session["cord"] != null)
{
if (context.Session["cord"].ToString() == cord)
{
if (username == "admin" && password == "admin")
{
context.Response.Write("Login successful!");
}
else
{
context.Response.Write("Login failed! Username and password are wrong!");
}
}
else
{
context.Response.Write("Verification code is wrong!" );
}
}
This is the code to determine login.
Okay, the above is the core code, I hope you can give me some advice. I also hope my notes are useful to you