Server-to-Browser WDDX Using JavaScript

WDDX has fantastic possibilities that extend well beyond server-to-server data sharing. If you use WDDX along with client-side JavaScript, it becomes possible to offload data processing of complex datatypes to a historically underused resource—the browser. What does this mean for you as a web developer? For starters, it means that you now have the ability to easily convert complex datatypes, such as arrays, structures, and record sets from CFML, to JavaScript objects that can then be manipulated by the browser. This opens a whole range of possibilities for building more sophisticated and dynamic user interfaces to your application data. It also means you can potentially improve the performance of applications that involve heavy data browsing and editing by moving the records to the browser and using JavaScript to let the user scroll through and edit as necessary. Once all changes have been made, the data can be serialized (using Java Script) back to a WDDX packet and then posted back to the server using a hidden form field.

Passing Data to JavaScript on the Browser

The CFWDDX tag provides two mechanisms for passing data to JavaScript on the browser. The first mechanism involves using CFWDDX to serialize CFML data into a WDDX packet, then using the CFWDDX tag to deserialize the WDDX packet to an equivalent JavaScript object. Example 20-15 shows how to do this by serializing a structure containing a stock quote to WDDX, then deserializing ...

Get Programming ColdFusion now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.