XML
  Home arrow XML arrow Page 4 - Building an AJAX-Based Chat: The Barebones...
IBM developerWorks
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Actuate Whitepapers 
VeriSign Whitepapers 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
XML

Building an AJAX-Based Chat: The Barebones Structure
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 31
    2005-11-08

    Table of Contents:
  • Building an AJAX-Based Chat: The Barebones Structure
  • Defining the application’s core logic: working with requester objects
  • Sending chat messages: defining the “sendMessage()” function
  • Checking for the progress of sender requests: defining the “senderStatusChecker()” function
  • Updating the display of messages: coding the “displayChatData()” function

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
    Iron Speed
     
    ADVERTISEMENT

    Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    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(senderXMLHttpObj.readyState==4){
            if(senderXMLHttpObj.status==200){
     // if status == 200 display chat data
     displayChatData(senderXMLHttpObj);   
            }
            else{
                alert('Failed to get response :'+
    senderXMLHttpObj.statusText);
            }
        }
    }

    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.

    More XML Articles
    More By Alejandro Gervasio


       · The capabilities of AJAX for developing Web applications that resemble desktop...
       · The method you are using for AJAX really limits your audience since you are using...
       · Hello,Thank you for commenting on the article. With reference to your opinion,...
       · Well written. Thank you.
       · Thank you for the kind comments on the article. Very much...
       · Hi. Your chat seems to be interesting though i didn't manage to put it working...
       · Hello Paulo,Thank you for commenting on my article. I've tested my chat...
       · Thanks for the great articles, I'm in the process of designing a user-to-user chat...
       · Thank you for your kind comments on my articles. I'm really glad to know that you're...
       · HiIt is very interesting and excellent. I am going to implement based on your...
       · Hello Upen,Thank you for the compliments on my AJAX article; they’re really...
       · Hai I am also thinking to implementing .do you give your code.I am also help...
       · Thank you for commenting on my AJAX article. Concerning your question, you can...
     

    XML ARTICLES

    - Path, Predicates, and XQuery
    - Using Predicates with XQuery
    - Navigating Input Documents Using Paths
    - XML Basics
    - Introduction to XPath
    - Simple Web Syndication with RSS 2.0
    - Java UI Design with an IDE
    - UI Design with Java and XML Toolkits
    - Displaying ADO Retrieved Data with XML Islan...
    - Widget Walkthrough
    - Introduction to Widgets
    - The Why and How of XML Data Islands
    - Creating an XUL App Installer
    - Overlays in XUL
    - Skinning Your Custom XUL Applications


    Iron Speed





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway