Passing Data to JavaScript Using <cfwddx>
So far in this chapter, you have seen how to pass variables from ColdFusion to JavaScript by generating the appropriate script code on the fly, using <cfoutput> and other basic CFML tags. The listings have worked out just fine; there is nothing wrong with this approach. For lack of a better term, I'm going to call this the roll-your-own approach to passing variables to JavaScript.ColdFusion provides a higher-level tool for passing variables to JavaScript: the CFML2JS action of the <cfwddx> tag. You were introduced to <cfwddx> in Chapter 16, "Using WDDX." That chapter explained how to use the tag to serialize and deserialize data in WDDX packets (a form of XML).This section will focus on a completely different use for <cfwddx>, which is passing variables to JavaScript. This use of <cfwddx> has nothing directly to do with WDDX packets or XML. While it is consistent with WDDX's overall mission (to make it really easy to transfer data from place to place), it is not really about the WDDX format per se.Instead of producing an XML version of a ColdFusion variable or value, this form of <cfwddx> produces a chunk of JavaScript code that, when executed by the browser's interpreter, re-creates the variable or value in the browser's memory. In other words, instead of converting your data into a WDDX packet, this method converts your data to a bunch of JavaScript code.
Using this Form of <cfwddx>
Chapter 16).Chapter 16, "Using WDDX", for details).