JavaScript
  Home arrow JavaScript arrow Page 3 - Browser-Server Dialogue
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 
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? 
JAVASCRIPT

Browser-Server Dialogue
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 3
    2006-10-05

    Table of Contents:
  • Browser-Server Dialogue
  • Solution for Call Tracking
  • Real-World Examples of Call Tracking
  • Call Tracking Alternatives

  • 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


    Browser-Server Dialogue - Real-World Examples of Call Tracking


    (Page 3 of 4 )

    Ajax Client Engine (ACE) library

    Li Shen's Ajax Client Engine (ACE) (http://www.lishen.name/) uses Call Tracking to ease development and harden the application in production. Among its many features are several related to Call Tracking:

    • Long calls are timed out.
    • Changes to XMLHttpRequest's response state are logged.
    • A service can be periodically polled.
    • The caller can declare exactly when the callback method should be invoked.

    AjaxCaller library

    The AjaxCaller library (http://ajaxify.com/run/Lib/js/ajaxCaller.js), used throughout the AjaxPatterns demos for Web Remoting, uses Call Tracking to pool Calls, which wrap XMLHttpRequest objects.

    libXmlRequest library

    libXmlRequest (http://www.whitefrost.com/reference/2005/09/09/ libXmlRequest.html) is another XMLHttpRequest wrapper. It keeps XMLHttpRequest objects in a pool so they can be reused, and tracks the response status in order to manage the pool.

    Code Example: Ajax Client Engine (ACE)

    In this example, well look at ACE's internal handling of call timeouts. The library consists of Requester objects, which wrap XMLHttpRequest objects. As explained earlier in the Solution, the wrapped XMLHttpRequest objects are created upon construction. When the wrapper is invoked to make a call, it creates a timer to cancel the request if it takes too long. The timer ID is held as an attribute of the wrapper.

      timeoutId = window.setTimeout(endRequest, request.callbackTimeout * 1000);

    To track the call, the wrapper registers itself as a request handler:

      function beginRequest()
     
    {
       
    ...
       
    requester.onreadystatechange = readystatechangeHandler;
       
    ...
     
    }

    Its handler is therefore called upon each change, and in the case of a complete call, cancels the timer:

      function readystatechangeHandler()     ...
        if (requester.readyState == Ace.ReadyState.Complete)
        {
          ...
          if (requester.status == Ace.Status.OK)
          {
             ...
             if (timeoutId)
             {
               window.clearTimeout(timeoutId);
               timeoutId = undefined;
             }
             ...
          }
       ...
      }

    More JavaScript Articles
    More By O'Reilly Media


       · This article is an excerpt from the book "Ajax Design Patterns," published by...
     

    Buy this book now. This article is excerpted from chapter 10 of the book Ajax Design Patterns, written by Michael Mahemoff (O'Reilly, 2006; ISBN: 0596101805). Check it out today at your favorite bookstore. Buy this book now.

    JAVASCRIPT ARTICLES

    - Comparing Fields and Customizing Error Messa...
    - Checking Numbers and File Extensions with jQ...
    - Validating Digits and Dates with jQuery`s Va...
    - Validating Ranges, Emails, and URLs with jQu...
    - More Uses for the jQuery Tooltip Plug-in`s b...
    - Building Image-Based Tooltips with the jQuer...
    - Using the jQuery Tooltip Plug-in`s bodyHandl...
    - Using Rangelength, Min and Max with the Vali...
    - Using Minlength and Maxlength with the Valid...
    - Modifying Tooltip Coordinates with the jQuer...
    - Applying a Fade Out Effect with the jQuery T...
    - Tracking Mouse Movements with the jQuery Too...
    - Checking Online Forms with the Validator jQu...
    - Nested JavaScript Functions as Objects
    - The jQuery Tooltip Plug-in







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek