util.Connect.asyncRequest('GET', sUrl, callback); #1
}
(annotation)<#1 With YUI we use the Connect object for Ajax connections>
As you can see, the code is pretty much the same. In this case, the class that wraps up XMLHttpRequest is
called YAHOO.util.Connect and we call the static method, asyncRequest to initiate the connection to the
server. Again a configuration object is used to define which call back functions we want to use, though this
time, I have created the object, callback, first and then assigned it to the function.
Using YUI or prototype makes development of Ajax applications much easier and less prone to error than
hand-coding from scratch. Obviously there are a lot of other client libraries out there such as Mootools and
dojo which are worth looking at before making a decision. For the remainder of this book, we will use the
Yahoo! User Interface library for no other reason than I quite like it and Yahoo! hosts the JavaScript files for
us, saving us a little bit of bandwidth. Now that we have a library to make development easier, we can now
look at how Ajax fits with the Zend Framework.
4.4 Using Ajax with the Zend Framework
The first thing to consider when using Ajax with the Zend Framework is that the Zend Framework does
not provide an Ajax components per-se, but the MVC system and other components such as Zend_Json make
it easy to add Ajax features to your application As throughout this book, maintenance of the application is a
key consideration and the Zend Framework??™s separation of the model and controller from the view makes it
easy to replace the standard HTML-based view of most pages with another view especially for Ajax requests.
Pages:
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134