[jQuery] Fetch (ajax) a file only if it's been modified
Hi all, I'm trying to fetch a file, but only if the Last-Modified
header has changed. What I have is a page that fetches a data file
every X seconds (20 in my case) and displays that info to the user.
That data file is updated on the server whenever a user takes specific
action.
It works fine doing this:
//refresh data every 20 seconds
setInterval(function() {
$('div#livedata').load('livedata_fetch.php')
}, 20000);
But that fetches the file every single time. It's not a big file, but
I really only need to fetch it if it's changed. I thought the
following would work, but it doesn't seem to, any ideas?
//refresh data every 20 seconds but only if data has changed
setInterval(function() {
$.ajax({
url: "livedata_fetch.php",
ifModified: true,
success: function(data){
$("div#livedata").html(data);
}
});
}, 20000);