开发者

process json returned from coldfusion cfc

Hi I have a form select bound to a cfc - i can see the json returned but its not displaying on my form - i have the code as below hope someone can help:

FORM

<script type="text/javascript">
// <!--
$(document).ready(function()
{
$("#CountriesList").change(function()
{
if($(this).val() != '')
{
$.ajax({
type: "POST",
url: "mycfc.cfc?method=GetCities&returnformat=json",
data: ({
CountryID: $(this).val()
}),
dataType: "xml",
success: function(xml)
{
$('#Cities option').remove();
$(xml).find('record').each(function()
{
$("#Cities").append('<option value="' + $(this).find('tape_width').text() + '">' + $(this).find('tape_width').text() + '<\/option&开发者_JS百科gt;');
});
}
});
}
});

})

// -->
</script>

<cfsilent>
<cfinvoke component="mycfc" method="CountriesList" returnvariable="CountriesList"/>
</cfsilent>
 <cfoutput>
 <label for="CountriesList">Select Country:</label>
 <select name="CountriesList" id="CountriesList">
<option value="" selected="selected">...</option>
 <cfloop query="CountriesList"><option value="#BAND#">#CountriesList.BAND#</option></cfloop>
</select>
<label for="Cities">Select City:</label>
<select name="cities" id="Cities"><option value="">...</option></select>
</cfoutput>

The actual CFC is as below:

<cfcomponent>
<cffunction access="remote" name="CountriesList" output="false" returntype="query">
<cfquery name="SelectAllCountries" datasource="test">
 SELECT DISTINCT BAND
 FROM FABRICS
 WHERE TYPE='venetian'
 AND isACTIVE='true'
 ORDER BY BAND
</cfquery>
<cfreturn SelectAllCountries>
</cffunction>
<cffunction access="remote" name="GetCities" output="false" returntype="query">
<cfargument name="CountryID" required="yes" type="any" default="" />
<cfquery name="Cities" datasource="test">
 SELECT TAPE_WIDTH
 FROM tapes
 WHERE SLAT_WIDTH='#arguments.CountryID#'
</cfquery>
<cfreturn Cities>
</cffunction>
</cfcomponent>

Could someone point out where am going wrong please?

Thanks


I fixed a similar problem I was jhaving by adding queryformat as follows:

$.getJSON("getContacts.cfc?method=getContacts&returnformat=json&queryFormat=column

prior to this I was seeing the json being returned (through firebug) but it was not dipslaying...

Hope it helps


If you're returning json, why are you specifying an XML datatype? Try

datatype: 'json'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜