Any idea why this jquery isn't working?

For discussions about game development that does not fit in any of the other topics.
Post Reply
Loopy

Any idea why this jquery isn't working?

Post 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).
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Any idea why this jquery isn't working?

Post 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');
}
The indelible lord of tl;dr
Post Reply

Return to “General Development”