Reputation: 115
Hi there I am looking for some hints to troubleshoot a problem I am having with ajax refresh , The problem is the div shows latest info on load but when it refreshes it is showing older data . The div shows the latest tracks played on air like I say when the page loads it shows the correct tracks but after 10 seconds when it reloads It is showing older tracks .
Here is my code ...
$(document).ready(function() {
$("#tracks").load("json.php");
var refreshId = setInterval(function() {
$("#tracks").fadeOut('slow').load("json.php").fadeIn('slow');
}, 10000);
$.ajaxSetup({ cache: false });
});
Any help figuring this problem out would be greatly appreciated
Upvotes: 1
Views: 539
Reputation: 205
This is probably caused by caching of the browser. You should explicitly turn off caching to avoid this.
In ASP you could/should set:
Response.CacheControl = "no-cache, no-store, must-revalidate"
Response.Expires = -1
See this topic for an excellent discussion about this.
Upvotes: 3
Reputation: 104
I've found disabling ajax caching doesn't work reliably in all browsers. To be sure to get fresh content, you could add some unique data to the query string, for example:
function rand() {
return Math.floor((Math.random()*99999)+10000);
}
...
$("#tracks").load("json.php?defeatCache="+rand());
Upvotes: 3