What I’m trying to achieve is that initially data will be loaded and then be updated every ten minutes using the same function.
Consider this code:
var updateNamespace = (function() {
var object = '#updates',
load = 'loader';
return {
update: function() {
$(object).addClass(load).load('update.php', function(reponse, status, xhr) {
if (status == 'error') {
$(this).html('<li>Sorry but there was an error in loading the news & updates.</li>');
}
$(this).removeClass(load);
});
}
}
})();
setInterval(updateNamespace.update(), 600000);
I get this error:
useless setInterval call (missing quotes around argument?)
How can I fix this?
What’s a better and more elegant way of writing this or using the setInterval function?
Thanks.
You need to use:
(Note the removed invocation() operator.)
Your code, as written, will actually invoke
updateNamespace.updatewhen you call setInterval. Hence,evaluates to
You want to pass
setIntervala REFERENCE to your function, not the result of its invocation.