XML
  Home arrow XML arrow Page 4 - Building an AJAX-Based Chat: Coding the Re...
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  
Moblin 
JMSL Numerical Library 
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: Coding the Receiver Module
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 13
    2005-11-15

    Table of Contents:
  • Building an AJAX-Based Chat: Coding the Receiver Module
  • Retrieving messages from the database: defining the “getChatData()” function
  • Building the chat layout: writing the “createMessageBoard()” and “createMessageBox()” functions
  • Registering chat users: defining a simple login page
  • Putting the pieces together: building the whole chat page

  • 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
     
     
    ADVERTISEMENT


    Building an AJAX-Based Chat: Coding the Receiver Module - Registering chat users: defining a simple login page


    (Page 4 of 5 )

    Before I begin defining the login page, which is useful for registering user nicknames, first allow me to show the corresponding screenshot, which is useful for illustrating how visitors log onto the application. Here is how this page looks:

    In the simplest sense, the above image depicts a simple login page, where users are asked to enter a nickname, in order to gain access to the chat page. Although the login process is pretty straightforward and easy to understand, let’s have a look at the basic structure of the login page, so you can see how nicknames are registered by PHP session variables. Here is the appropriate (X)HTML markup, together with the PHP snippet that stores the nicknames:

    <?php
    // register nickname as session variable
    // & redirect to chat page
    if($_POST['enter']){
        session_start();
        $_SESSION['user']=$_POST['nickname'];
        header('location:ajaxchat.php');
    }
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
    Transitional//EN" "
    http://www.w3.org/TR/xhtml1/DTD/xhtml1-
    transitional.dtd
    ">
    <html>
    <head>
    <title>CHAT LOGIN</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <style type="text/css">
    body {
         background: #eee;
         margin: 0px;
         padding: 0px;
    }
    h1 {
         font: bold 36px Arial, Helvetica, sans-
    serif;
         text-align: center;
    }
    div {
        width: 50%;
        background: #99f;
        border: 1px solid #000;
        padding: 20px;
        margin-left: auto;
        margin-right: auto;
    }
    p {
        font: normal 12px Verdana, Arial,
    Helvetica, sans-serif;
        color: #000;
    }
    </style>
    <script language="javascript">
    window.onload=function(){
        var nick=document.getElementsByTagName
    ('form')[0].elements['nickname'];
        if(!nick){return};
        nick.focus();
    }
    </script>
    </head>
    <body>
    <h1>AJAX-BASED CHAT SYSTEM</h1>
    <div>
    <form action="<?php echo $_SERVER['PHP_SELF']?
    >" method="post">
    <p>Enter your nickname <input type="text"
    name="nickname" />
    <input type="submit" name="enter"
    value="Go!" /></p>
    </form>
    </div>
    </body>
    </html>

    As shown above, the logic of the login page is extremely simple. It exposes a login form, which uses the “Observer” pattern for submitting the data to itself. After the user has submitted the form, the PHP snippet registers the entered nickname in a “user” session variable, and redirects the visitor to the “ajaxchat.php” file, where the chat page will be displayed. Of course, I haven’t included any data checking line within the PHP script, in order to keep the code as simple as possible, but usually a login page (even the simplest one) will require writing some kind of data checking code.

    Having defined the corresponding login page for the chat application, it’s time to put some of the pieces together and show the complete source code for the chat page, including both the “sender” and “receiver” modules, as well as some basic (X)HTML markup and CSS rules. Want to know how the whole chat page is assembled? Just keep reading.

    More XML Articles
    More By Alejandro Gervasio


       · Over this second article, the "receiver" module of the chat application is properly...
       · This is my first foray into AJAX and DOM, and I this tut was the best place to...
       · Thank you for your compliments on my AJAX tutorial. I'm really glad to know that...
       · Nice articleIsnt it bad pratice to call a function recursively without ever exiting...
       · Thank you for commenting on my article. Comming to your question, recursion can be...
       · Nice article,It would be great if they had a link to an example at the beginning...
       · Thank you for the kind comments on my AJAX tutorial. Of course, when applicable,...
       · Nice article & very interesting, since I have been looking for a thorough, detailed...
       · Hello Rasmus,I'm glad to know that my AJAX chat was what you were looking for....
       · I loved your article. It helped me understand AJAX more. BUT, this does not want...
       · Thank you so much for the kind comments on this tutorial. It's good to see it's been...
       · Nice article. I had just finished my own AJAX chat tutorial when I ran across yours....
       · I'd like to thank you for commenting on my AJAX-based chat tutorial, particulary if...
     

    XML ARTICLES

    - 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
    - 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







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