- When jquery loads a page, it is only loaded once. There are two solutions.
- 1jQuery provides a method to prevent ajax from using cache,
- <script type="text/javascript" language="javascript">
- $.ajaxSetup({
- cache: false//close AJAX cache
- });
- </script>
- This method must be executed once every time the page is loaded, otherwise it will only be valid for the first time, and other loads will also read the cached page
- 2 The second is to modify the url address loaded by load
- For example, you can add another time parameter to the url . This method is also used in wap1.0 to avoid reading the cache .
- There are two other methods found before, which do not work for this problem:
- 1. Set the cache of html
- <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
- <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
- <META HTTP-EQUIV="Expires" CONTENT="0">
- 2 , java settings cache
- <%
- request.setAttribute("decorator", "none");
- response.setHeader("Cache-Control","no-cache"); //HTTP 1.1
- response.setHeader("Pragma","no-cache"); //HTTP 1.0
- response.setDateHeader ("Expires", 0); //prevents caching at the proxy server
- %><pre name= "code" class = "java" >Jquery $.get method cache problem
- In the IE series, the $.get() method will cache the returned result when the url address is fixed, causing unexpected problems. But under Firefox, it will not be cached.
- There are many ways to solve this problem, the most direct is to replace the $.get() method with $.ajax(), and then configure cache: false . I don't like the cumbersome configuration method of $.ajax(), which can be implemented in the simplest way:
- Add a new random parameter after the data of $.get(), such as {data: mydata, stamp: Math.random() }, because the data is different each time, the data returned after the request will not be cached.
- In addition, you can also change $.get() to $.post(), which can also solve this problem.
- The solution once and for all is to set the global parameters, $.ajaxSetup({cache: false }); After this setting, basically all get requests jquery will automatically add additional parameters of the word _1948838, which is similar to the above solution in general .
- E.g:
- $.get("ProvinceListByCountryIDHandler.ashx", { "cid": $drpCountry.val(), "time": new Date().getTime() }, function(data, returnStatus) {})
Solve jquery load, get method cache data problem
Guess you like
Origin http://10.200.1.11:23101/article/api/json?id=326883405&siteId=291194637
Recommended
Ranking