KillerFish
KillerFish

Reputation: 5170

How to make notification on message send like Facebook

How a notification can be shown after we are receiving a new message like FACEBOOK is displaying without refreshing a page. ( facebook is showing RED color notification after receiving a new message).

Thank You

Upvotes: 2

Views: 6335

Answers (4)

Ben
Ben

Reputation: 1

If ive understood you correctly you need to look up a technology called AJAX, its a combination of JavaScript and XML which allows the sending and receiving of data behind the scenes ie without needed to refresh the page. Theres plenty of tutorials/information out there about it and its not difficult to get the hang of, hope this helps.

Upvotes: 0

Samet Atdag
Samet Atdag

Reputation: 992

There are two ways out there, you poll, or Comet.

  1. Polling means you ask this question to your server periodically: "is there a new message?" with Ajax. If there is a new message, server returns it or the number of new messages.
  2. Or you can implement some kind of Comet. Comet is a technology which contains open connections between client and server. Since there is an open connection, your server can send new information to clients.

After the number of new messages arrived to you, you can edit your DOM via javascript to show a red notification whereever you want.

Upvotes: 8

CarpeNoctumDC
CarpeNoctumDC

Reputation: 1760

Easiest way is to use jquery to update the content of a div at a sepecific interval...

#idofdivtoupdate

as it says.. the id of the div you want to auto update...

setinterval is in miliseconds.. (so 5000 checks every 5 seconds)

function updatecontent(){
$('#idofdivtoupdate').load('yourserverscript.php'); 
} 

setInterval("updatecontent()", 5000 );

Upvotes: 1

Matt Asbury
Matt Asbury

Reputation: 5662

You need to use setInterval to periodically check for any new updates and then, if they are found, use ajax to pull in the message.

Upvotes: 3

Related Questions