I have the following code:
var c = null; c = Titanium.Network.createHTTPClient(); var url = 'example.com'; c.open('GET', url); Titanium.API.log('info', url); c.onload = function() { Titanium.API.log('info', 'onload'); setInterval(getPeople(), 5000); }; c.send();The code should access the getPeople() function every 5 seconds, but it does not. In fact, the application exists prematurely.
what Im I doing wrong?
3 Answers
Accepted Answer
Exactly right Alexander. And just to complete the answer:
// Store so we can clearInterval(peopleInt); later var peopleInt = setInterval(getPeople, 5000);If you need to call your function with some arguments, you can wrap it in an anon function:
var peopleInt = setInterval(function() { getPeople(arg) }, 5000);
You need to pass a reference, if you put parenthesis you execute the function directly.
// Store so we can clearInterval(peopleInt); later var peopleInt = setInterval(getPeople, 5000);
Hello, Try this :
I think you need to write function name in quotes.
setInterval("getPeople()", 5000);
Your Answer
Think you can help? Login to answer this question!