user1049057
user1049057

Reputation: 459

cfajaxproxy returning undefined

I am using cfajaxproxy to fetch the data from db and display it. For example, I have a dropdown which have the country code. On change of the countrycode, it should display the correct country name from db. but its returning undefined value. Below is the code

<cfajaxproxy cfc="cfcProxy" >

<script language="javascript">
function getCountry(code)
{
var code=document.getElementById('code').value;
var object=new cfcProxy();
object.setCallbackHandler(getCountryResult);
object.setErrorHandler(errorhandler);
object.getCountrylist(code);
}
function getCountryResult(result)
{   
alert(result.value);
document.getElementById('country').innerHTML=result;
}
function errorhandler()
{
alert("Problems running proxy");
}

Country code: <select name="code" id="code" onchange="getCountry();">
<cfoutput>
<cfloop query="getCountrylistfrmDB">
<option value="#code#">#code#</option>
</cfloop>
</option>
</cfoutput>
</select><br><br>

<div id="country"></div>

cfcProxy.cfc is

<cffunction name="getCountrylist" access="remote" returntype="query">
<cfargument name="code" required="yes">
<cfquery name="getCountrylistfrdisp" datasource="test">
select country from countrycode where code = "#arguments.code#"->
</cfquery>
<cfreturn getCountrylistfrdisp>
</cffunction>

Upvotes: 1

Views: 593

Answers (1)

Jake Feasel
Jake Feasel

Reputation: 16955

You're returning a query from your cfc but referencing result.value. Use console.log(result) to see exactly what properties are available for you to reference - I'm pretty certain "value" isn't one of them. Also, I'm pretty sure assigning the innerHTML to the result object itself won't work - that'll have to be the correct property too.

Upvotes: 2

Related Questions