I have a stat.dat file in which there is a number and it calls for include "stat.dat"; How to make this div block update every 10 seconds for example (there will be a lot of blocks)
- if this is the number of views that is recorded in the file - BedOmar
- developer.mozilla.org/en-US/docs/Web/API/WindowTimers/…/api.jquery.com/jquery.ajax - E_p
- On pure js? Or jQuery? - koks_rs
- don't care somehow ... - BedOmar
|
1 answer
If you are using jQuery, then something like this:
$(document).ready(function () { var intervalID = window.setInterval(myCallback, 10000); function myCallback() { $.ajax({ url: "index.php", dataType: "json", type: 'POST', }).done(function (data) { $("#divId").text(data); }).fail(function (jqXHR, textStatus) { console.log(jqXHR); }); } } on server side:
$filePath = "путь к файлу/stat.dat"; if (file_exists($filePath)) echo file_get_contents(); else echo 0; |