
Example 5-6. XmlHttpService.cfm
<cfsetting enablecfoutputonly="true" />
<cfsilent>
<cfinvoke component="Shipping"
method="getShippingOptions" argumentcollection="#url#"
returnvariable="myResult" />
<cfoutput>
<cfxml variable="userXML">
<options>
<cfloop index="i" from="1" to="#ArrayLen(myResult)#">
<option>
<service>#myResult[i].service#</service>
<price>#myResult[i].price#</price>
</option>
</cfloop>
</options>
</cfxml>
</cfoutput>
</cfsilent>
<cfcontent reset ="yes" type="text/xml; charset=UTF-8">
<cfoutput>#userXML#</cfoutput>
The
backend for the XML or plain text frontend appears in
Example 5-7.
Example 5-7. Shipping.cfc
<cfcomponent>
<cffunction name="getShippingOptions" access="remote"
returntype="array">
<cfargument name="zipcode" type="any" required="yes">
<cfargument name="pounds" type="any" required="yes">
<cfset var options=ArrayNew(1)>
<cfset var baseCost=(zipcode / 10000) + (pounds * 5)>
<cfset options[1] = structNew() />
<cfset options[1].service="Next Day">
<cfset options[1].price=baseCost * 4>
<cfset options[2] = structNew() />
<cfset options[2].service="Two Day Air">
<cfset options[2].price=baseCost * 2>
<cfset options[3] = structNew() />
<cfset options[3].service="Saver Ground">
<cfset options[3].price=baseCost>
<cfreturn options>
</cffunction>
76 | Chapter 5: Working with the Server
Komentáře k této Příručce