Have you checked that it's not being cached by the browser?
Have you also ensured that the AJAX request isn't 404ing and is actually receiving valid data?
It looks like it'd be very "cachable" as it's a GET request and doesn't have a query string.
A few things that might prevent caching:
- Return headers from the server to prevent caching
- Change it to a POST request
- Append a different query string to each request
For more info on these
Headers:
https://stackoverflow.com/a/21609642/5302749
Add these before your response:
header('Expires: Sun, 01 Jan 2014 00:00:00 GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', FALSE);
header('Pragma: no-cache');
POST request
https://api.jquery.com/jquery.post/ -
Pages fetched with POST are never cached, so the cache and ifModified options in jQuery.ajaxSetup() have no effect on these requests.
Appending a different query string each time
As @Barmar mentioned you can also provide cache: false
as an option I believe some versions of jQuery won't allow you to pass the option directly to $.get so I've changed it to $.ajax, also error handling is always a good idea so I've added in a .fail
callback.
$(function() {
function reloadTable(){
$.ajax({
url: "pot1.php",
cache: false,
})
.done(function( data ) {
$( "#pot" ).html( data );
})
.fail(function(jqXHR, textStatus, errorThrown){
console.log('Error: ' + textStatus ); // error handling here
});
}
reload = setInterval(reloadTable, 1000);
});
Or manually adding a parameter (this only looks smaller as no error handling is included) - I think it's better to not reinvent the wheel and just use jQuery's built in functions where possible.
$(function() {
var reloadCount = 0;
function reloadTable(){
reloadCount++;
$.get("pot1.php?reloadCount=" + reloadCount, function(data) {
$("#pot ).html(data);
});
}
reload = setInterval(reloadTable, 1000);
});