In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail how to solve the problem of ajax session expiration. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
If mishandled, it will affect the user experience, and it may also cause inexplicable problems.
Combined with my own thinking and the reference of relevant content on the Internet, the following solutions are given. Each scheme has its own advantages and disadvantages.
Scenario 1: check whether the returned content returned by AJAX has a tag
In the web system, when the session expires, when the user has an operation, the system will generally return to the login interface.
Ask the user to re-enter the user name and password. When the session expires, the content returned by the AJAX request should be the page of the login interface
Content (that is, the html code of the page of the login interface). By determining whether the returned content is used to determine whether the session is out of date.
Content returned by var result=request.responseText;/* ajax * /
If (result.indexOf ('') >-1) {/ * there is a html tag * /} in the returned content
Or
Var r=//ig
If (r.test (result)) {/ * there is a html tag in the returned content * /}
Through the above method, we can determine whether the session is out of date, and then handle the exception according to the specific business.
Scenario 2: the result returned has a flag of whether the session is out of date. Some people also call it true/false mode.
This solution is generally used in conjunction with json.
For example, the returned result is:
Var res= {
"result": true,/*session does not expire, false (session expires) * /
"data": "/ * other data * /
}
If (res ["result"])
{
/ * session has not expired * /
} else {
/ * session expires * /
}
Option 3: use timestamps
Make a global variable on the page
Var startDate; / * time when ajax last visited the server, Date type * /
If (new Date (). GetTime ()-startDate.getTime ()
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.