Prevent JQUERY.load from cache

It seems like using IEquery.load in IE9 will extract data from the browser's cache, and therefore the “real-time” effect of loading AJAX content does not work. Is there any switch to make jquery.load get the data fresh?

Thansk!

+6
source share
4 answers

The option to disable caching is available in jQuery if you use the $.ajax low-level method. This is not represented in the simplified signature for load . You could simulate this instead, ensuring that the URL is always unique. You can put the current time in milliseconds at the end of the URL to achieve this, since it will almost always be unique:

 url += '?_=' + (new Date()).getTime(); 

(It is assumed that url is a string containing the request URL, and that it does not have any request parameters at this time.)

+10
source

Or you can use $.ajax and set the cache parameter to false , which will cause jQuery to add a timestamp to the request URL under the hood:

 $.ajax( { url: "foo.html", type: "GET", cache: false, success: function(html) { $("#foo").html(html); } }); 
+7
source

In the contents of the page you are trying to load, first send the header so that the request does not use the cache ...

For example, at the top of the code add the following lines

 <?php header("Cache-Control: no-cache"); header("Pragma: no-cache"); //Other page contents that have to be loaded ?> 
+2
source

Or you can use

 elem.load(url, "f" + (new Date()).valueOf()); 

so that each query gets a new unique value added to the query string

0
source

Source: https://habr.com/ru/post/893422/