I'm using this ajax function to reload an html page to a division in web page.
<script>
$('#scene_container').load('scene.html', function () {
cache: false
});
</script>
html:
<div id="scene_container"></div>
But most of the time it loads cached webpage. How to load the original html page?
I'm using this ajax function to reload an html page to a division in web page.
<script>
$('#scene_container').load('scene.html', function () {
cache: false
});
</script>
html:
<div id="scene_container"></div>
But most of the time it loads cached webpage. How to load the original html page?
Share Improve this question asked May 1, 2014 at 12:04 Asanka HerathAsanka Herath 1,6113 gold badges20 silver badges36 bronze badges 1-
You set
cache = false
in the callback function. That does not have any effect on the ajax call. You should use the $.ajax function to disable caching. Or as @maj suggests use a url time parameter. – devqon Commented May 1, 2014 at 12:08
2 Answers
Reset to default 5Preventing cache is not available with the load method unless you disable it globally
But you can make sure no data will be loaded from cache by appending a time parameter to the request URL
url = "scene.html";
url += '?_=' + (new Date()).getTime();
To control caching on a per-request basis, you need to use a more plex function like $.ajax()
.
Insert this at the top of your script:
$.ajaxSetup ({
// Disable caching of AJAX responses
cache: false
});
MANUAL
ANother way is to use an unique id like this to the end of the url:
$('#scene_container').load('scene.html?uid'+uniqueId());