function getUsers(column, id) {
	$.get('userlist.php', {column: column, id: id}, function(output) {
		$("#userlist").html(output);
	});
	setTimeout(getUsers(column, id), 5000);
}

userlist.php checks for users online.

i want it to check every 5000ms (for example, doesnt have to be that)

Firebug is giving me 'too much recursion' errors.

I've used this exact code structure before successfully.... help would be greatly appreciated!

Aeterna,

This is tricky.

I'm not sure why the code works at all because setTimeout(getUsers(column, id), 5000); appears to be invalid. I would choose to use setTimeout(function()(getUsers(column, id);), 5000); . This might in itself fix the bug.

Thoughts ....
Strictly speaking there's no recursion, as setTimeout starts a fresh call-stack at each iteration. However, the presence of column, id as arguments means that these variables are held in a fresh, nested closure at each iteration. At some threshold, the number of nested closures (rather than recusions per se) exceeds the number allowed by the javascript engine. In this regard, the difference between recursions and nested closures is somewhat academic.

If I'm right (and my first suggestion doesn't work), then the workaround is not to pass column, id to getUsers . Instead, set column and id as outer variables (global if you must) at the point where getUsers is first called. This will avoid the need for closures and should allow garbage collection to do its thing.

Airshow

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.