我试图通过ajax返回一个struct数组来提供自动完成功能。 我想从我要填充文本框的页面中通过ajax调用 getEmployeeName 。
test.cfc如下:
<cfcomponent>
<cffunction name="getEmployeeName" access="remote" returnformat="JSON" >
<cfargument name="term" type="string" required="yes">
<cfset var returnArray=ArrayNew(1) />
<cfset term=#Ucase(term)#>
<cfquery name="getEmps" datasource="mines">
...
<!--- my query ---!>
</cfquery>
<cfoutput>
<cfloop query="getEmps">
<cfset empStruct = StructNew() />
<cfset empStruct["label"] = #emp_name# & " " &#desg_desc# & " " & #unit_name# />
<cfset empStruct["value"] = #cpf_no#>
<cfset ArrayAppend(returnArray,empStruct) />
</cfloop>
</cfoutput>
<cfreturn #serializeJSON(returnArray)#>
</cffunction>
ajax调用如下:
$("#task_coordinator").autocomplete({
source: function (request, response) {
$.ajax({
url: "test.cfc?method=getEmployeeName",
type: "GET",
data: request,
success: function (data) {
console.log(data);
console.log(data.array([label]));
},
error: function(jqXHR, extStatus,errorThrown){
alert(errorThrown);
}
});
},
select: function (event, ui) {
}
,minLength:5
});
我尝试直接通过链接调用该方法,看看它是否正常工作。在那时它只返回json数据而不是这些额外的信息。我的输出在json数据之前有额外的脚本:
<script type="text/javascript">/* <![CDATA[ */_cf_loadingtexthtml="<img alt=' ' src='/CFIDE/scripts/ajax/resources/cf/images/loading.gif'/>";
_cf_contextpath="";
_cf_ajaxscriptsrc="/CFIDE/scripts/ajax";
_cf_jsonprefix='//';
_cf_websocket_port=8577;
_cf_flash_policy_port=1243;
/* ]]> */</script><script type="text/javascript"
src="/CFIDE/scripts/ajax/messages/cfmessage.js"></script>
<script type="text/javascript" src="/CFIDE/scripts/ajax/package/cfajax.js">
</script>
<script type="text/javascript" src="/CFIDE/scripts/cfform.js"></script>
<script type="text/javascript" src="/CFIDE/scripts/masks.js"></script>
<script type="text/javascript" src="/CFIDE/scripts/cfformhistory.js">
</script>
<script type="text/javascript">/* <![CDATA[ */
ColdFusion.Ajax.importTag('CFAJAXPROXY');
/* ]]> */</script>
<script type="text/javascript">/* <![CDATA[ */
ColdFusion.Ajax.importTag('CFFORM');
/* ]]> */</script>
<script type="text/javascript">
<!--
_CF_checkCFForm_1 = function(_CF_this)
{
//reset on submit
_CF_error_exists = false;
_CF_error_messages = new Array();
_CF_error_fields = new Object();
_CF_FirstErrorField = null;
//display error messages and return success
if( _CF_error_exists )
{
if( _CF_error_messages.length > 0 )
{
// show alert() message
_CF_onErrorAlert(_CF_error_messages);
// set focus to first form error, if the field supports js focus().
if( _CF_this[_CF_FirstErrorField].type == "text" )
{ _CF_this[_CF_FirstErrorField].focus(); }
}
return false;
}else {
return true;
}
}
//-->
</script>
[{"value":47455,"label":"BANTHIA ANUJA RAVINDRAKUMAR GRADUATE EXECUTIVE TRAINEE(E2) CENTRAL ESTABLISHMENT"}]
有人可以告诉我为什么这个额外的剧本即将到来。提前谢谢!
答案 0 :(得分:0)
在ColdFusion Administrator中,选择Debugging&amp;记录&gt;调试器设置。你应该在那里找到一些设置来帮助调试AJAX请求。如果选中它,请尝试将其关闭。
以下是一些可能有用的信息。 http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec10e40-8000.html