4.3.2 The YUI library from Yahoo!
The Yahoo! User Interface (YUI) also provides a set of user interface widgets along with some underlying
classes to make the creation of Ajax applications easier. The attraction of the YUI is that a big company is
supporting it and it has great documentation including examples. As with prototype, there is a good community
using the library that has produced extensions that enhance the standard components.
Changing our example JavaScript so that it uses the YUI results in very similar code to the prototype
example. We add the required files to the HTML (yahoo.js and connection.js) and then the rest of the work is
in ajax.js (see listing 4.5).
Listing 4.5: ajax.js: Integrating YUI into our example Ajax application
var handleSuccess = function(o) {
if(o.responseText !== undefined){
document.getElementById('message').innerHTML = o.responseText;
}
}
Licensed to Menshu You
Please post comments or corrections to the Author Online forum at
http://www.manning-sandbox.com/forum.jspa?forumID=329
var handleFailure = function(o) {
document.getElementById('message').innerHTML = "";
}
function check(name)
{
var sUrl = "ajax.php?name=" + name;
var callback =
{
success: handleSuccess,
failure: handleFailure
};
var request = YAHOO.
Pages:
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133