<cfwddx>To turn the preceding code example into a WDDX packet, you can use a tag called <cfwddx>, like this: <cfwddx action="CFML2WDDX" input="#products#" output="NewPacket"> CAUTION Note the pound signs (#) around the value for the input attribute. If you forget them, ColdFusion thinks you are trying to serialize the literal string products. Table 35.1 lists the attributes of the <cfwddx> tag.
Table 35.2 lists the possible values for the action attribute.
NOTE JavaScript and ColdFusion are only two of the languages that understand WDDX. Some others are PHP, Perl, ASP, Python, and Java. If you have a query record set called GetStates and want to serialize it into a WDDX packet, you can type: <cfwddx action="CFML2WDDX" input="#GetStates#"> Because the preceding <cfwddx> code doesn't have an output attribute, the data is output directly to the page itself rather than being put into a variable. CAUTION WDDX packets don't like special characters such as < or > outside the XML tags. When you're developing applications, you probably have the ColdFusion debugging settings turned on in ColdFusion Administrator. The debugging is displayed at the bottom of your HTML page using HTML code. This means that when your WDDX packet is written to the page, it becomes corrupted by the extra HTML debugging information. To deal with this problem, always place the tag <cfsetting showdebugoutput="No"> at the top of your page. It suppresses debugging on the page. TIP Two ColdFusion functions that are helpful for creating valid WDDX packets are XMLFormat() and IsWDDX(). The former converts special characters in data to an acceptable XML format. The latter verifies that the WDDX packet is valid. |