tags:

views:

15

answers:

1

In gmail, I see that the inbox is automatically updated when an email is arrives. How is it possible in PHP or ASP to handle such sort of updating client side website from the server? I guess in the browser chat it is the same process. Thanks.

A: 

This is called AJAX (Asynchronous JavaScript and XML), in which client-side scripts do request without refreshing the page altogether, and then changes page parts according to the returned response.

aularon
In that case, the client has to (Poll) continuously ask the server if there is a new email. Is there any other way that the server itself notifies its clients?
Holly
That would be complicated, and it would involve complicated approaches in the clientside and the serverside, like a java-app that opens a socket to the server and the server echos data upon availability. Most implementations does the normal "polling thing", like here on SO, while I'm writing it is polling the server for newly added answers.
aularon
Thank you for the information.
Holly
Could you please tell me how we could do client side polling?
Holly
you should have a script running every 20 seconds for example, and a serverside page, the script ajax request would request the page sending `last_email_date` parameter, for example, the page would check the database (or any other source) for new emails based on the specified criteria. and return xml/json/html of the content, then the script would use that response to update user interface. That's the basic scinario.
aularon