www.developer.com/lang/article.php/3600611
|
April 21, 2006 The introduction of Ajax techniques to the web has spurred a series of JavaScript libraries designed to aid in cross-browser Ajax coding. A search for Ajax libraries on your favorite search engine will reveal a plethora of libraries claiming to be the best for such tasks. Recently, Yahoo! released some of its JavaScript utilities to the public; among them is the Connection Manager. With Ajax making heavy use of XMLHttp, many developers are looking for ways to equalize the differences between browser implementations. The Yahoo! Connection Manager does this by handling all of the processing behind the scenes, exposing a simple API that frees developers from cross-browser concerns. Before beginning, make sure you read the Yahoo! license agreement for JavaScript components at http://developer.yahoo.net/yui/license.txt. It's a standard BSD-style license, but you should be sure to read it over anyway. You can download the Connect Managed code from http://developer.yahoo.net/yui/connection/index.html#download. The code download includes the source code as well as documentation, but no examples. SetupThere are two JavaScript files necessary to use the Connection Manager: <script type="text/javascript" src="/js/YAHOO.js"> <script type="text/javascript" src="/js/connection.js"> With these files included in your page, you are now ready to begin using the Connection Manager. Basic RequestsThe Yahoo! Connection Manager uses a different methodology than you may be used to for sending XMLHttp requests. Instead of creating objects, the Connection Manager exposes several static methods to handle requests. The method you'll use most often is YAHOO.util.Connect.asyncRequest(request_type, url, callback, postdata); The first argument, request_type, is the type of HTTP request to make: "get" or "post". The second argument is simply the URL of the request. The third argument is a callback object containing methods to handle the response from the request. This object has the following basic form:
As you can see, this object has two methods: The final argument of |