Yesterday encountered a problem such as:
IE Browser, Web site can not log on and exit normally.
That's weird. The previous comparison ignores ie. Using Firefox google test is good.
After repeated investigation, finally found the problem.
I am using the jquery get method to obtain
The cache is generated on IE, and I use the IE Debug Check tool to check the cached data to update it. I don't know what to say. Then I'll just change it to post.
Another method is to pass a variable value to the server at the time of get. You can also resolve this issue.
IE Access policy: Internet Options--browsing history--setting--The Internet temporary files option is changed to every time you visit a Web page
1: After the Ajax requested page, add a random function, we can use the random time function
Add T=math.random () after the URL sent by javascript
For example: url+ "&" + "t=" +math.random (); or new Date ();
Another: Baidu to the information
———————–
Yesterday in the use of prototype Ajax to business logic to take data found that each new browser can display the results of the database update, if the Refresh browser will not change. However, after the deletion of the IE temporary files, the refresh will be displayed correctly. As a result, I conclude that IE would cache the data returned by AJAX requests. Some data have been found that generally reflects the Ajax get way will be cached, and some netizens proposed the solution:
1, in the service End plus header ("Cache-control:no-cache, must-revalidate");
2, in the AJAX send the request before adding Anyajaxobj.setrequestheader ("if-modified-since", "0″);"
3, in the AJAX send the request before adding Anyajaxobj.setrequestheader ("Cache-control", "No-cache");
4, after the Ajax URL parameters plus "? fresh=" + math.random (); Of course, the parameter fresh can be arbitrarily taken.
5, the fourth method is similar to the third, after the URL parameter plus "? timestamp=" + New Date (). GetTime ();
6. Replace get with post: not recommended
I am not satisfied with the above points,
1 in the case of the server plus, the problem is Ajax out, it should be resolved, regardless of the service side of the matter;
2 and 3 of the situation, I now use prototype, not ordinary Ajax native statements, so should be in the premise of prototype solution;
4 and 5, why add an argument after the address? This parameter is not what my business logic needs (this method I haven't run through);
6 of the case, instead of post, I would have been a link can be done, and sometimes necessary to use the link, but to change to form, this is not a bit stupid.
The solution to this problem should be in the premise of prototype. Check the prototype documentation to see that there is a requestheaders option that is responsible for processing the requested header information, which is also mentioned in the above method for no cache setting, So let's just set this option on the line. Just add one sentence to the prototype AJAX configuration:
The code is as follows |
Copy Code |
Requestheaders: [' Cache-control ', ' no-cache ', ' if-modified-since ', ' 0 '], |
Example:
The code is as follows |
Copy Code |
var myajax = new Ajax.request ("/personal/operatepage.jsp", { Method: ' Get ', Parameters: "action=addfriend&ids=" + Escape (IDs), Requestheaders: [' Cache-control ', ' no-cache ', ' if-modified-since ', ' 0 '], Oncomplete:function (msg) { alert (Msg.responsetext); } }); |
JSP code
The code is as follows |
Copy Code |
Public Class Cachingheaderinterceptor extends Abstractinterceptor { private static final long Serialversionuid = 1L ; public String Intercept (actioninvocation invocation) throws Exception { actioncontext context = Invocation.getinvocationcontext (); httpservletresponse response = (httpservletresponse) context.get (strutsstatics.http_response); if (response!= null) { response.setheader ("Cache-control", "No-cache"); & Nbsp; response.setheader ("Pragma", "No-cache"); response.setheader ("Expires", "-1"); } return Invocation.invoke (); } } |