Home arrow XML arrow Page 4 - Building an AJAX-Based Chat: The Barebones Structure

Building an AJAX-Based Chat: The Barebones Structure

Chat programs are common on the web these days. HTTP-based versions were often built as Java applets, but today, developers have a wider range of options when building chat programs. This article gets you started with building one that uses AJAX as the workhorse for sending out http requests without the need for page reloading.

Author Info:
By: Alejandro Gervasio
Rating: 5 stars5 stars5 stars5 stars5 stars / 43
November 08, 2005
  1. · Building an AJAX-Based Chat: The Barebones Structure
  2. · Defining the application’s core logic: working with requester objects
  3. · Sending chat messages: defining the “sendMessage()” function
  4. · Checking for the progress of sender requests: defining the “senderStatusChecker()” function
  5. · Updating the display of messages: coding the “displayChatData()” function

print this article

Building an AJAX-Based Chat: The Barebones Structure - Checking for the progress of sender requests: defining the “senderStatusChecker()” function
(Page 4 of 5 )

Once a user has submitted a message, the application needs to determine whether the post request has been successfully completed. If it has, the display of messages will be immediately updated, which translates into a faster visual response for the user that originally sent the message. Therefore, considering that updating the messages currently displayed can be easily handled after the insertion of a new message in the database table, here is the definition for the “senderStatusChecker()” function:

function senderStatusChecker(){
    // check if request is completed
 // if status == 200 display chat data
            alert('Failed to get response :'+

As you can see, this function is a lot simpler than it really seems. What it does essentially is check the status of the post request responsible for inserting a new message into the database. In that case, the display of messages needs to be quickly updated. If you study the above code, you’ll see that the updating process is performed by the “displayChatData()” function, which accepts a requester object as the unique incoming parameter.

Having illustrated how the progress of the requests made by the “sender” object is checked in, let’s now take a look at the “displayChatData()” function, and see how the display of chat messages is properly updated. Just keep reading.

blog comments powered by Disqus

- Open XML Finally Supported by MS Office
- XML Features Added to Two Systems
- Using Regions with XSL Formatting Objects
- Using XSL Formatting Objects
- More Schematron Features
- Schematron Patterns and Validation
- Using Schematron
- Datatypes and More in RELAX NG
- Providing Options in RELAX NG
- An Introduction to RELAX NG
- Path, Predicates, and XQuery
- Using Predicates with XQuery
- Navigating Input Documents Using Paths
- XML Basics
- Introduction to XPath

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials