AJAX - The Complete Reference

(avery) #1

PART II


Chapter 5: Developing an Ajax Library 211


In order to check whether a request is still in progress, YUI provides a useful method,
isCallInProgress(), to which the reference to the connection in question is passed in as
the parameter.

if (YAHOO.util.Connect.isCallInProgress(transaction))
YAHOO.util.Connect.abort(transaction);
else
alert("Connection was not active");

YUI manages readyState by including a polling mechanism to continually look at the
value. The default for this in the particular build evaluated is 50 ms, though it is possible to
modify this value using the setPollingInterval() method and passing it a value in
milliseconds.

YAHOO.util.Connect.setPollingInterval(100) ;

Finally, YUI also supports the setProgId(id) method for future proofing in case other
ActiveX XHR signatures should be needed. Another ActiveX creation string could be passed
in if you want to add it to the mix like so:

YAHOO.util.Connect.setProgId("Msxml2.XMLHTTP.6.0");

This covers the public methods and properties of the 2.3.0 version of YUI. We provide
an explorer program at http://ajaxref.com/ch5/yuiexplorer.html to exercise various
aspects of the connection library shown in Figure 5-2. For further details, such as the private
implementation of the library, we suggest you turn to the YUI source itself, as it is both
highly readable and well commented.

Other YUI Features

YUI provides many features beyond the Connection Manager. Table 5-6 provides an
overview of the features that the library provides, although its likely features will have been
added or the names will have changed by the time you read this.
Many of the aspects of the library are, of course, not Ajax specific, but we show them to
give you a sense of how expansive thinking can get when you consider using Ajax. It is our
opinion that YUI is an excellent library that is well supported and documented. However,
there are always alternatives so let’s take a quick look at another popular library for
comparison’s sake.

NNOT EOTE Some third parties have taken ideas from or built technologies around popular
libraries such as Yahoo’s YUI library to some great success. Extjs (http://extjs.com) has been
cited by many as one particular extender to keep an eye on.

Introduction to Prototype


Prototype (www.prototypejs.org/) is a popular JavaScript library that aims to ease all
JavaScript coding including Ajax applications. The Prototype library is commonly found
working in conjunction with frameworks like Ruby on Rails and is the basis of other
frameworks, notably script.aculo.us (http://script.aculo.us/). While quite popular,
Free download pdf