Prev | Current Page 123 | Next

Rob Allen, Nick Lo, and Steven Brown

"Zend Framework in Action"


Integration into the Zend Framework takes two forms: handling the Ajax request from the user within the
controller and providing the JavaScript elements to handle the response from the server back to the client.
4.4.1 The server-side of an Ajax request
From the Zend Framework??™s point of view, an Ajax request looks remarkably like any other request into the
application. The most significant difference is that the response back to the client is a either snippet of HTML,
XML or JSON. To respond to an Ajax request is, therefore, just a case of ensuring that we use a different view
and the easiest way to do this is to use a different controller. The advantage of the MVC design pattern comes
into play now as the business logic is in the Model and so can be reused without any changes when adding
Ajax to an application.
The controller
When providing controller actions that respond to Ajax calls, the view must not send back full HTML pages,
but must instead send HTML fragments, JSON or XML data. If we take the simple example application, then
the controller will require two actions; one for the displaying the page and one for responding to the Ajax
request. Displaying the page, as shown in Listing 4.6, should now look familiar.
Licensed to Menshu You

Pages:
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
tłumacz niemieckiego hosting zakłady bukmacherskie serwis drukarek katowice petrozawodzkich.waw.pl