How Facebook chat is working? Can anyone give me idea? I mean they are using websocket or AJAX? How they have implemented it?
It's a comet (see wikipedia) model:
Comet is a web application model in which a long-held HTTP request allows a web server to push data to a browser, without the browser explicitly requesting it. Comet is an umbrella term, encompassing multiple techniques for achieving this interaction. All these methods rely on features included by default in browsers, such as JavaScript, rather than on non-default plugins. The Comet approach differs from the original model of the web, in which a browser requests a complete web page at a time.
Example of comet framework is APE. It is for javascript, however comet can be written not only in javascript.