Sending Chat Messages
One aspect of writing AJAX enabled applications is that one can no longer pass off Javascript as an afterthought. If you're intent on creating dynamic web applications using AJAX, visual effects, and funky new age interfaces then you'll just have to start recognising that Javascript is going to be a primary development language.
An introduction to Javascript is out of this tutorial's scope, but I'll hit the high points as I move along.
Initiating an XHR Request
XMLHttpRequest (hereafter dubbed "XHR") is a native browser object in most modern browsers with the exception of Internet Explorer 6 where it is an ActiveX object. It allows a scripting language like Javascript to create background connections to the server which do not reload the current web page. Because accessing the XHR is a complicated process, I'll skip the fine details and introduce Prototype's Ajax.Request class which buries the detail behind a simple interface.
Using AJAX with Prototype is covered in detail at http://www.sergiopereira.com/articles/prototype.js.html#UsingAjax.