AJAX - The Complete Reference

(avery) #1

PART II


Chapter 9: Site and Application Architecture with Ajax 437


Applying the Templates
The first library method we introduce in the template facility is AjaxTCR.template
.translateFile(templatefilename, data). You pass this method the URL of the
template file you want to apply and a JSON object that has the various name-value pairs to
be used to populate and control the template’s rendering. For example, given our rating
system, we might now define a callback function for onSuccess called showResults(),
which might look something like this:

function showResults(response)
{
var ratingData = AjaxTCR.decodeJSON(response.responseText);
var renderedResponse = AjaxTCR.template.translateFile(

FIGURE 9-5 Testing our template code
Free download pdf