Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
8
rated 0 times [  14] [ 6]  / answers: 1 / hits: 23301  / 13 Years ago, wed, january 4, 2012, 12:00:00

I want to periodically query a PHP script for new messages. To do so, I'm using the setInterval() function and AJAX.



$(document).ready(function(){

var queryInterval = 1000; /* How fast we query for new messages */

setInterval(getMessages(), queryInterval);

function getMessages() {
console.log(tick);
}

});


However, when I look at the Javascript console, I'm only seeing tick once. I've made sure that the console doesn't ignore any more logs of the same strings, so if the code was working properly it should show tick in the console every second.



Anyone know what could be going wrong here?


More From » setinterval

 Answers
28

Change:



setInterval(getMessages(), queryInterval);


To:



setInterval(getMessages, queryInterval);

[#88232] Tuesday, January 3, 2012, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
neildrews

Total Points: 166
Total Questions: 103
Total Answers: 85

Location: Moldova
Member since Sat, Aug 6, 2022
2 Years ago
neildrews questions
Fri, Feb 18, 22, 00:00, 2 Years ago
Tue, Oct 12, 21, 00:00, 3 Years ago
Tue, Mar 23, 21, 00:00, 3 Years ago
Sun, Aug 16, 20, 00:00, 4 Years ago
;