我想通过POST响应使用jQuery ajax获取一段数据,但我似乎无法显示数据。这是我正在使用的代码。使用ColdFusion和jQuery显示ajax响应
$(document).ready(function(){
$('#contentdiv').html(' ');
$("#idm").change(function(){
var formval = {idm:$(this).val()};
$.ajax({
type: "POST",
url: "request_processor.cfm",
dataType: "json",
data: formval,
success: function(response){
$('#contentdiv').fadeIn(2000).append(response.DESCRIPTION);}
});
});
});
这是我从CFC回来的JSON。
{"DESCRIPTION":"Global Alpha I Benchmark"}
这里是request_response.cfm
<cfset oData = CreateObject("component","menudata")>
<cfset oData.setDataSource(dsn)>
<cfset theData = oData.getMenuData(FORM.idm)>
<cfset oJSON = createObject("component","cfjson")>
<cfset theResults = oJSON.encode(theData)>
<cfoutput>#theResults#</cfoutput>
有什么问题的代码?
感谢
您希望从模板返回什么样的数据(仅供参考:它不是CFC,除非您的URL错误)。 – 2012-03-21 19:14:14
你是什么意思“似乎无法显示数据”?究竟发生了什么?如果你在成功回调中使用'console.log(response.DESCRIPTION)',你会得到什么? – 2012-03-21 19:21:48
假设您从CF返回的JSON是正确的,这看起来像一个JS问题。您是否在Firebug控制台中看到任何错误? – 2012-03-21 19:31:31