SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 182 | Next

Jonathan Snook, Aaron Gustafson, Stuart Langridge, and Dan Webb

"Accelerated DOM Scripting with Ajax, APIs, and Libraries"


??? onSuccess: Behaves just like the object and fires when the call has successfully completed.
??? onXXX: Where X is the HTTP status code; unlikely to be something you??™d use very often
because 200 is the most common return.
Some nice features of Prototype include its automatic handling of JSON. If the contenttype
returned from the server is text/javascript or application/javascript (or a few other
variations), the responseText will automatically get parsed by its JSON filter. Alternatively,
CHAPTER 5 n AJAX AND DATA EXCHANGE 124
you can pass data in on the X-JSON header but the amount of data you could pass in through
that is limited (this would be a reasonable place to put JSON-based error messaging, as covered
earlier).
Ajax.Updater
Ajax.Updater, which is a specialization of the Ajax.Request object, takes responseText and
automatically inserts it into the HTML element of your choosing:
new Ajax.Updater(container, url, options)
The options parameter is exactly the same as before, except with a couple of additional
options, most notably the insertion property. By default, the Updater replaces the content
within the element. However, the contents can be appended to what is already there with
the insertion parameter. The insertion parameter takes an Insertion object (another Prototype
class) that enables you to specify whether the contents come before the element
(Insertion.Before), at the top of the element (Insertion.


Pages:
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194