Converting CFML Data to a JavaScript Object

The following example demonstrates the transfer of a cfquery result set from a CFML page executing on the server to a JavaScript object that is processed by the browser.

The application consists of four principal sections:

The following example uses the cfsnippets data source that is installed with ColdFusion:

<!--- Create a simple query  --->
<cfquery name = "q" datasource ="cfsnippets">
  SELECT Message_Id, Thread_id, Username, Posted 
  FROM messages
</cfquery>

<!--- Load the wddx.js file, which includes the dump function --->
<!--- requests to the server --->
<script type="text/javascript"
  src="/CFIDE/scripts/wddx.js"></script>

<script>
  // Use WDDX to move from CFML data to JS
  <cfwddx action="cfml2js" input="#q#" topLevelVariable="qj">
  
  // Dump the record set to show that all the data has reached
  // the client successfully.
  document.write(qj.dump(true));
</script>


Note

To see how cfwddx Action="cfml2js" works, view the source to the page in your browser.