Dear Friends,

I'm developing a website that can show online users, When ever a user logged we can update the status to "Online" On our database. Now i'm using AJAX.

Is it possible to show the online users without refreshing a page ? That means timed interval for a ajax function.

Checking database for online users every secound using ajax or javascript ? like facebook and gmail. Please help me.

Thanks in advance.

<html>
<head>
<script type="text/javascript">
function timeMsg()
{
var t=setTimeout("alertMsg()",3000);
}
function alertMsg()
{
alert("Hello");
}
</script>
</head>

<body>
<form>
<input type="button" value="Display alert box in 3 seconds"
onclick="timeMsg()" />
</form>
</body>
</html>

Dear makman99,

Thanks for the reply.. but there he used onClick function on a input device. But here i need automatically refresh a div with ajax. That means Its check every time to database and display online friends. I think u got this..

First you create a action page in php which will return you latest info you want to display.
I mean I guess you know using ajax or jquery to post and retrive data.

Now You call that ajax/jquery function using timer

jquery tutorial u may find here
http://phpacademy.org/videos/index.php?all

krish, those links were examples. You merely need to replace on_click functions with on_load

<body onLoad="StartUpdate()">
<script>
function UpdateOnlineUsers()
{
...
}

function StartUpdate()
{
setInterval("UpdateOnlineUsers()",1000); //Updates online users every second
}
</script>


...
</body>

Thanks makman99,

Its working great

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.