Exchanging Data via XML
73
Converting CFML Data to a JavaScript Object
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:
•
Running a data query
•
Calling the WDDX JavaScript utility
•
Specifying the conversion type and the input and output variables
•
Calling the conversion function
•
Outputting the object data in HTML
This example uses a registered ColdFusion 4.0 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>
<script language=javascript>
<!--- 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'>
<!--- Recordset dumping routine --->
function dumpWddxRecordset(r)
{
// Get row count
nRows = r.getRowCount();
// Determine column names
colNames = new Array();
i = 0;
for (col in r)
{
if (typeof(r[col]) == "object")
{
colNames[i++] = col;
}
}
// Dump the recordset data
o = "Dumping recordset...<p>";
Содержание COLDFUSION STUDIO 4.5-USING COLDFUSION...
Страница 1: ...Allaire Corporation Using ColdFusion Studio ColdFusion Studio 4 5 for Windows 95 98 NT4 2000...
Страница 16: ...xvi Contacting Allaire...
Страница 90: ...82...
Страница 130: ...122...
Страница 133: ...141 Two VTML tags CAT and E let you customize the content of these dialog boxes...
Страница 182: ...190...