0

Everything is good, working, but is this a good way to refresh some data to display in the index, any suggestion will help

$(document).ready(function () {

setInterval(function () {
    $.ajax({
        url: 'dashboard/reserv_load_today.php',
        success: function (data) {
            var json = JSON.parse(data);
            $('#reserve_today').html(json.TODAY);
        }
    })

    $.ajax({
        url: 'dashboard/last_update.php',
        success: function (data) {
            var json = JSON.parse(data);
            $('#last_update').text(json.LAST);
        }
    })
}, 3000);

});
Twisty
  • 30,304
  • 2
  • 26
  • 45
James
  • 235
  • 1
  • 2
  • 10
  • 1
    You could reduce your GET requests if you make a single script to act as an API. In this way you make one call to the script and then split the result to where you need them. At present, you will be opening 2 Requests at the same time, and if you have multiple Users at the site, this may reach the max limit for the socket connections. You could potentially DOS your page. Specially if the PHP page takes time to load or supply results. Make sure that scripts are properly closing all connections to help avoid pile up. – Twisty Feb 21 '22 at 00:42
  • 1
    sse are also an option, easy to add: https://stackoverflow.com/questions/49080653/how-do-i-put-this-on-real-time-i-already-put-async-true-but-it-doesnt-work/49081040#49081040 – Lawrence Cherone Feb 21 '22 at 00:44

0 Answers0