Home arrow JavaScript arrow Page 3 - Browser-Server Dialogue
JAVASCRIPT

Browser-Server Dialogue


If you're wondering how to handle browser-server information flow, especially when dealing with web remoting, you've come to the right place. This article, the first of a multi-part series, discusses call tracking; future articles in the series will explain other ways to handle this communication. This article is excerpted from chapter 10 of the book Ajax Design Patterns, written by Michael Mahemoff (O'Reilly, 2006; ISBN: 0596101805).

Author Info:
By: O'Reilly Media
Rating: 3 stars3 stars3 stars3 stars3 stars / 3
October 05, 2006
TABLE OF CONTENTS:
  1. · Browser-Server Dialogue
  2. · Solution for Call Tracking
  3. · Real-World Examples of Call Tracking
  4. · Call Tracking Alternatives

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

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;
         }
         ...
      }
   ...
  }


blog comments powered by Disqus
JAVASCRIPT ARTICLES

- More Top jQuery Tutorials for Beginners
- More Top jQuery Plugins for Menus
- Top jQuery Tutorials for Beginners
- New UI Framework and SDK for JavaScript Rele...
- JavaScript OpenPGP Tool, Node.js 0.6.3 Avail...
- Yahoo Releases Cocktails Language and Develo...
- Customizing jQuery Slideshows: Dynamic Contr...
- Customizing jQuery Slideshows: the animate()...
- Customizing jQuery Slideshows: slideUp() and...
- Customizing jQuery Slideshows: hide() and sh...
- Web Workers: Performing Calculations in Para...
- More Top JavaScript Frameworks and Libraries
- More Dynamic jQuery Styling Techniques
- The Top JavaScript Libraries
- The Top JavaScript Frameworks

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



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