Use ajax to obtain the session implementation code in ASP

Source: Internet
Author: User

Because I use the ff browser, I have never found any problems. When I submitted it to the user last week, I was surprised that it was invalid after I used IE to log on. The result is true .. Very stable
The logon code is as follows: Copy codeThe Code is as follows: // query whether a session exists on the slave server
J. ajax ({
Type: "GET ",
Url: "sessioncheck. asp ",
Data :"",
Timeout: 1000,
Error: function (){
Alert ('Sorry, server is busy now! ');
},
Success: function (comments_data ){
If (comments_data = 1 ){
El. createDialog (opts );
J. startOver ();
}
Else {
Var SQL = selectSQL (searchkey, stype );
Window. location. href = SQL;
}
}
});

In general, sessioncheck. asp is nothing more than querying sessions. The Code is as follows:Copy codeThe Code is as follows: if session ("username") = "" then
Response. Write ("1 ")
Else
Response. Write ("2 ")
End if

The result is that the session IE ("username") is useless, and the timeout setting is useless.

I went online for half a day and found that there were quite a few problems. Finally, I found the cause: the cache problem.

When an asynchronous get is obtained, if the url remains unchanged, the information in the cache is directly called, and the value in the session is never obtained.

The solution is simple. There are a lot of google "asp clear cache.
Finally, add a section in sessioncheck. asp, as shown below:Copy codeThe Code is as follows: Response. Buffer = True
Response. ExpiresAbsolute = Now ()-1
Response. Expires = 0
Response. CacheControl = "no-cache"
If session ("username") = "" then
Response. Write ("1 ")
Else
Response. Write ("2 ")
End if

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.