2011-11-17 157 views
1

我正在使用cfajaxproxy从数据库中获取数据并显示它。例如,我有一个有国家代码的下拉菜单。在更改国家代码时,它应该从数据库中显示正确的国家名称。但其返回的未定义值。以下是代码cfajaxproxy返回undefined

<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> 

回答

2

您正在从您的cfc返回查询,但引用了result.value。使用console.log(结果)查看具体哪些属性可供您参考 - 我非常确定“价值”不是其中之一。另外,我非常确定将innerHTML分配给结果对象本身将不起作用 - 这也必须是正确的属性。