I have this code:
$(document).ready(function(){
var callPage = function(){
$.post('/pageToCall.php');
};
setInterval('callPage()', 60000);
});
and it gives me the error ReferenceError: Can't find variable: callPage. Why?
Try setInterval(callPage, 60000);.
If you pass a string to setInterval, then this string is evaluated in global scope. The problem is that callPage is local to the ready callback, it is not global.
There is hardly ever a reason to pass a string to setInterval (setTimeout). Always pass a function (to avoid exactly this kind of errors).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With