我正在开发一个聊天应用程序,该应用程序使用对Coldfusion Web服务的ajax调用,该服务将返回结构中的值。这是js
JS:
$.ajax({
type: "POST",
url: $bPath,
contentType: "application/JSON; charset=utf-8",
data: data,
beforeSend: function() {
//alert(data);
},
error: function(data,status,error){
alert('Something went wrong: '+data+', '+status+', '+error);
},
dataType: 'JSON'
}).done(function(api) {
console.log( api );
$('#chatBox').append('<div class="messageEntry"><span>'+api.TIMESTAMP+': </span><span><strong>'+api.NAME+'</strong></span>: <span>'+api.MESSAGE+'</span></div>');
$('#chatBox').scrollTop($('#chatBox')[0].scrollHeight);
$("#messageInput").val('');
});
这是CFC
CFC:
<cfcomponent>
<cffunction name="newMessage" access="remote" returntype="Struct" returnformat="JSON">
<cfset params = toString( getHttpRequestData().content ) />
<cfset args = #deserializeJSON(params)# />
<cfset timeStamp = #args.time# />
<cfset newMessage = #args.message# />
<cfset userID = #args.userID# />
<cfquery name="qryemp" datasource="HR">
select EmployeeID, name_last, name_first, Email
from tblRegionIIEmployee
where Username = <cfqueryparam cfsqltype="cf_sql_varchar" value="#userID#">
</cfquery>
<cfset myResult={timeStamp="#args.time#", name="#qryemp.name_first# #qryemp.name_last#", message="#args.message#"} />
<cfreturn myResult>
</cffunction>
</cfcomponent>
我没有在任何地方显示任何错误,在firebug中它只显示响应为null。为什么Web服务不返回我的数据?