• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 20. Sharing Data with WDDX > Server-to-Browser WDDX Using JavaScript

20.5. 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.

20.5.1. 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 the WDDX packet containing the structure to a JavaScript struct. The JavaScript code that creates the struct object is created dynamically using the CFWDDX tag. The JavaScript struct is then looped over and the contents output to the browser.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint