Ajax session Expiration issue

Source: Internet
Author: User
Tags date exception handling extend html tags interface return client

If improper handling will affect the user experience, it may also produce inexplicable problems.
Combined with their own thinking and online related content reference, give the following solutions.
Scenario 1: Check if the returned content of Ajax returns has In the web system, when the session expires, when the user has operations, the system will normally return to the landing interface.
Let the user re-enter the user name and password. When the session expires, the AJAX request to return the content should be the Landing interface page
Content (that is, the HTML code of the page on the login interface). Determines whether the session expires by using the var result=request.responsetext;/* ajax return Content * *
if (Result.indexof (' <HTML> ') >-1) {/* return content with HTML tags */}
var r=/if (r.test (Result)) {//* return content with HTML tags/}
The above method can determine whether the session expires, and then according to the specific business of exception handling.
Scenario 2: The returned results are marked with the expiration of the session. There are also people called True/false mode
This solution is typically used in conjunction with JSON.
If the result returned is:
var res={
' Result ': True,/*session does not expire, false (session expired) * *
"Data": "* * Other information * *
if (res["result"])
/*session not expired
/*session Expired *
Scenario 3: Use time stamps
Get a global variable on the page
var StartDate; /*ajax the last time the server was accessed, date type * *
if (new Date (). GetTime ()-startdate.gettime () <30*60*1000)
/* Assume session expires in 30 minutes * *
/*session not expired
/*session Expired *
Ha ha! Don't trust the Client
Scenario 4: Extend session Expiration
There are performance issues with this scenario
4.1: Extend session Expiration time
4.2:client round the server. (Ajax round-robin or Client,server keep long connections)

Related Article

Cloud Intelligence Leading the Digital Future

Alibaba Cloud ACtivate Online Conference, Nov. 20th & 21st, 2019 (UTC+08)

Register Now >

Starter Package

SSD Cloud server and data transfer for only $2.50 a month

Get Started >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.