Page 1 of 1
Any idea why this jquery isn't working?
Posted: Wed Aug 03, 2011 10:27 pm
by Loopy
I'm just trying to call a php file every 10 seconds but am getting firebug errors:
Code: Select all
setInterval(function() {
$.get("update.php")
}, 10000);
Error I'm getting: "Error: missing } after fuction body"
Then it tells my the problem is in my jquery file (1.6.2).
Re: Any idea why this jquery isn't working?
Posted: Wed Aug 03, 2011 10:39 pm
by Jackolantern
You have a stand-alone statement in the middle of your function ($.get("update.php")) that needs to have a semi-colon after it. The JS interpreter is getting tripped up. It should be:
Code: Select all
setInterval(function() {
$.get("update.php");
}, 10000);
If this starts getting more complicated, you should perhaps consider breaking this away and changing the anonymous function to a named function outside of the setInterval call for the sake of clarity. In the simple state it is in now it is fine but if it grows it may keep it more tidy to just make it separate:
Code: Select all
var si = setInterval(callUpdate, 10000);
function callUpdate() {
$.get('update.php');
}