AJAX - The Complete Reference

(avery) #1

PART II


Chapter 5: Developing an Ajax Library 201


Introduction to YUI


The first library we discuss is the Yahoo User Interface Library (YUI), found at http://
developer.yahoo.com/yui/. The syntax of this library will be quite familiar since many of
its conventions were supported in the education library. However, even after a quick
perusal and comparison to the book library, it will certainly become apparent that YUI is
not the most expansive of the various JavaScript libraries with Ajax support in terms of the
widgets and features it offers. However, YUI is certainly the best documented and most
tested of the libraries. Given that YUI is used in the production of various public Yahoo
web applications, it has passed a usage trial far exceeding even the most popular
competing libraries.

Method Description
AjaxTCR.data.encodeValue(str) Encodes the passed string in a properly
escaped application/x-www-form-
urlencoded manner.
AjaxTCR.data.decodeValue(str) Decodes any passed value in
application/x-www-form-
urlencoded format into a standard
string format.
AjaxTCR.data.encode64(str) Encodes the given string in base64.
AjaxTCR.data.decode64(str) Decodes the given string from base64.
AjaxTCR.data.serializeForm(form,
encoding,trigger,evt)

Inspects each element in the given
form and encodes it using the encoding
Content-Type specified. Valid
Content-Type's are text/xml,
application/json, text/plain,
and application/x-www-form-
urlencoded.
AjaxTCR.data.serializeObject(payload,
obj,encoding)

Loops through an object of name-value
pairs and encodes each using the
encoding Content-Type specified.
AjaxTCR.data.encodeJSON(obj) Translates the given object into a JSON
string
AjaxTCR.data.decodeJSON(str) Translates the given string into a
JavaScript object.
AjaxTCR.data.encodeAsHTML(str) Translates the tags in a string to escaped
characters (< and >). The function
will also translate \n into <br />.
AjaxTCR.data.serializeXML (xmlObject) Returns any passed XML tree structure
back as a string; in other words, serialized.

TABLE 5-4 AjaxTCR.data Methods
Free download pdf