The following example demonstrates the transfer of a CFQUERY result set from a CFML template executing on the server to a JavaScript object that is processed by the browser.
The application consists of five principal sections:
This example uses a registered ColdFusion datasource and can be run from ColdFusion Server.
<!--- Create a simple query ---> <CFQUERY NAME = 'q' DATASOURCE ='snippets'> SELECT Message_Id, Thread_id, Username, Posted from messages </CFQUERY> <!--- Cache the JavaScript so that subsequent requests will ---> <!--- use the cached version rather than making additional ---> <!--- requests to the server ---> <SCRIPT LANGUAGE="JavaScript" SRC="/CFIDE/scripts/wddx.js"></SCRIPT> <!--- Bring in WDDX JS support objects A <SCRIPT SRC=></SCRIPT> can be used instead wddx.js is part of the ColdFusion distribution ---> <CFINCLUDE TEMPLATE='/CFIDE/scripts/wddx.js'> <!--- Use WDDX to move from CFML data to JS ---> <CFWDDX ACTION='cfml2js' input=#q# topLevelVariable='q'> <!--- Dump the recordset ---> q.dump(true); </SCRIPT>
Note | To see how CFWDDX Action="cfml2js" works, view the source to the page. |