my application (ASP.NET MVC) shows a page which loads data constantly, at certain intervals.
The jQuery script calls a controller and this one renders a different pa
You might want to try this instead:
[EDIT] removed function being returned to setInterval
$(document).ready(function() {
$('#loading').html("
").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 were loading your spinner every time you were loading appointments. Also you were passing in times
into the window.setInterval
.
My code testing this function is:
$(document).ready(function() {
$('#loading').html("
").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);
}
});
}
The php file:
//contentServer.php