XML
  Home arrow XML arrow Page 2 - Take AJAX to your Email Inbox: Developing ...
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  
Mobile Linux 
App Generation ROI 
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

Take AJAX to your Email Inbox: Developing the Client-side Application Layer
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 6
    2006-04-05

    Table of Contents:
  • Take AJAX to your Email Inbox: Developing the Client-side Application Layer
  • Connecting to the mail server: defining the "sendHttpRequest()" function
  • Collecting connection data: defining the "getFormValues()" function
  • Displaying email messages: defining the "fetchMessages()" function
  • Initializing the POP3 client: defining the "initializeUserPanel()" function
  • Integrating the POP 3 client: listing the complete source code of the application

  • 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


    Take AJAX to your Email Inbox: Developing the Client-side Application Layer - Connecting to the mail server: defining the "sendHttpRequest()" function


    (Page 2 of 6 )

    In order to make things really simple, the process for connecting to the mail server will be performed using AJAX, which means having to work with "XMLHttpRequest" objects, and some of their useful properties. This way, all the connection tasks can be handled without troubling the application too much with complex JavaScript code.

    That said, here is the "sendHttpRequest()" function, which for obvious reasons, will request the PHP file responsible for connecting to the mail server and fetching email messages. Its definition is as follows:

    function sendHttpRequest(url,callbackFunc,respXml){
        var xmlobj=null;
        try{
            xmlobj=new XMLHttpRequest();
        }
        catch(e){
            try{
                xmlobj=new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch(e){
                alert('AJAX isn't supported by your browser!');
                return false;
            }
       }
       xmlobj.onreadystatechange=function(){
            if(xmlobj.readyState==4){
                if(xmlobj.status==200){
                    respXml?eval(callbackFunc+'(xmlobj.responseXML)'):eval
    (callbackFunc+'(xmlobj.responseText)');
                }
            }
       }
       // open socket connection
       xmlobj.open('POST',url,true);
       // send http header
       xmlobj.setRequestHeader('Content-Type','application/x-www-
    form-urlencoded; charset=UTF-8');
       // get form values and send http request
       xmlobj.send(getFormValues(document.getElementsByTagName
    ('form')[0]));
    }

    If you've ever used AJAX within your Web applications, the above function should be pretty familiar to you. As you can see, it takes three input parameters: the URL which the script will be pointed to (url), the name of the callback function to be called up when the http request has been completed (callbackFunc), and finally an XML flag (respXML), which indicates to the function whether server data should be fetched as XML or not.

    Having explained the meaning of the incoming arguments, let's see how they're used inside the function. The main purpose of the function is only to fetch a PHP file from the Web server; then it instantiates an "XMLHttpRequest" object, after solving the pertinent incompatibilities between Internet Explorer and the other browsers.

    Now, take a deep breath and put your head to work for a minute: remember that the connection area I created within the user interface was designed as a simple web form? Fine, so the function must send out the data entered on this form to establish the connection to the mail server. This is done simply by triggering a POST request to the server and specifying the corresponding HTTP header that tells the server to treat the data as submitted by a regular form.

    Here there's something worth noting. Take a look at the line below:

    xmlobj.send(getFormValues(document.getElementsByTagName('form')
    [0]));

    As you can see, the function sends the POST request, after collecting the values entered on the form, by utilizing the "getFormValues()" function. This takes the form in question and extracts its values to be transmitted to the server. But, in fact I am getting ahead of myself because this function hasn't been defined yet. Thus, after explaining how the "sendHttpRequest()" function works, it's time to write down this new function.

    More XML Articles
    More By Alejandro Gervasio


       · In this second article, all the JavaScript functions that comprise that client-side...
     

    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 5 hosted by Hostway
    Stay green...Green IT