Several solutions for Ajax session expiration issues _ajax related

Source: Internet
Author: User
Tags exception handling html tags
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. Each scenario has different pros and cons, welcome
Please correct me.
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 */}
Or
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
}else{
/*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
}else{
/*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

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.