954,597 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Ajax Timed Intervel : For Online Friends

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.

krishwebdesigne
Light Poster
27 posts since May 2011
Reputation Points: 14
Solved Threads: 1
 
makman99
Junior Poster in Training
68 posts since Jan 2010
Reputation Points: 12
Solved Threads: 13
 
<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..

krishwebdesigne
Light Poster
27 posts since May 2011
Reputation Points: 14
Solved Threads: 1
 

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

urtrivedi
Nearly a Posting Virtuoso
1,306 posts since Dec 2008
Reputation Points: 257
Solved Threads: 270
 

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>
makman99
Junior Poster in Training
68 posts since Jan 2010
Reputation Points: 12
Solved Threads: 13
 

Thanks makman99,

Its working great

krishwebdesigne
Light Poster
27 posts since May 2011
Reputation Points: 14
Solved Threads: 1
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: