It was actually simple. But I still encountered a problem that was not taken into account before I did it: the ajax cache problem. Therefore, the seemingly easy problem should be taken strictly. This is the quality that programmers should have.
Let's not talk much about it. The following is what happens during runtime.
H2. file description
Default. aspx, main demo page
GetSessionData. aspx: ajax call page
I am familiar with jquery. js and js frameworks.
H2. code analysis
The code is very simple. It mainly focuses on the cache of ajax, that is, you have set a new session value, but the old value is obtained by using ajax. In depth, this is not just an ajax cache problem, it should be related to the http protocol itself
There are many ways to invalidate the ajax cache. Here we use the server side to set GetSessionData. aspx. cs
Using System;
Using System. Data;
Using System. Configuration;
Using System. Collections;
Using System. Web;
Using System. Web. Security;
Using System. Web. UI;
Using System. Web. UI. WebControls;
Using System. Web. UI. WebControls. WebParts;
Using System. Web. UI. HtmlControls;
Public partial class GetSessionData: System. Web. UI. Page
{
Protected void Page_Load (object sender, EventArgs e)
{
Response. Cache. SetCacheability (HttpCacheability. NoCache );
Response. Write (Session ["current-date"]);
}
}
Note Line 16: Response. Cache. SetCacheability (HttpCacheability. NoCache );
This line of code allows the client to re-read from the server without using the cache.
I hope this article will help you.