Instead, you can try:
[EDIT] remote function returns to setInterval
$(document).ready(function() { $('#loading').html("<img src='Images/bigloader.gif' />").hide(); ScheduledAction(LoadAppointments, -1, <%=Model.RefreshTimeout %>); }); function ScheduledAction(func, times, interval) { var ID = window.setInterval(function() { if (times > -1) { if (--times <= 0) window.clearInterval(ID); } func(); }, interval); } function LoadAppointments() { $("#AppointmentsList").empty(); $('#loading').show(); $.get(UrlAction, function(data) { if (data != '') { $('#AppointmentsList').append(data); $('#loading').hide(); } else { $('#loading').fadeOut(3000); } }); }
I noticed that you downloaded your counter every time you downloaded appointments. Also you went through times in window.setInterval .
My code checking this function:
$(document).ready(function() { $('#loading').html("<img src='loader64.gif' />").hide(); ScheduledAction(LoadAppointments, 1, 100); }); function ScheduledAction(func, times, interval) { var ID = setInterval(function() { if (times > -1) { if (--times <= 0) clearInterval(ID); } func(); }, interval); } function LoadAppointments() { $("#content").empty(); $('#loading').show(); $.get('contentServer.php', function(data) { if (data != '') { $('#content').append(data); $('#loading').hide(); } else { $('#loading').fadeOut(3000); } }); }
Php file:
source share