我正在使用cfajaxproxy从db获取数据并显示它。例如,我有一个包含国家代码的下拉列表。更改国家代码时,应显示数据库中的正确国家名称。但它返回的是未定义的值。下面是代码
<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>发布于 2011-11-17 15:26:18
你从你的cfc返回了一个查询,但是引用了result.value。使用console.log(result)来确切地查看哪些属性可供您引用-我非常确定"value“不在其中。此外,我非常确定将innerHTML赋值给result对象本身是行不通的--这也必须是正确的属性。
https://stackoverflow.com/questions/8162853
复制相似问题