Returning Array from CFC to JavaScript
I am trying to write a javascript that talks to a CFC and I need the CFC to return an Array that I can read back into the javascript (as a js array) and then loop through that list.
So in the CFC I create an array something like:
<CFFUNCTION name="getCity" access="remote" returnType="array">
<CFSET var result = ArrayNew(2)>
<CFSET result[0][1] = 1>
<CFSET result[0][2] = “Vancouver”>
<CFSET result[0][1] = 2>
<CFSET result[0][2] = “Detroit”>
<CFSET result[0][1] = 3>
<CFSET result[0][2] = “Miami”>
<CFRETURN result>
</CFFUNCTION>
Then in the JS return function:
function returnCity(returnArray) {
for (var i=0; i<returnArray.length; i++) {
document.formname.cityID.options.value = returnArray[0];
document.formname.cityID.options.text = returnArray[1];
}
}
