JQuery自动完成远程数据(COLDFUSION)

我是JQuery的新手,试图从ColdFusion查询中提取远程数据,以便在我的文本框中显示。

在调用我的CFC时,我在firebug中收到错误:

未捕获的TypeError:不能使用’in’运算符来搜索’453′

我不知道这可能是什么意思。 我可以看到这是从我的数据库中提取数据,因为在我的控制台输出中,我看到了我的数据:

[{"value":1,"label":"Test article"}] jquery-1.10.2.js:997 

有人可以帮忙解决这个错误吗?

完整的HTML代码:

     Untitled Document     <!--- --->  $(function() { $( "#searchField" ).autocomplete({ source: function(request, response){ $.ajax({ url: "kb/cfcs/search.cfc?method=lookupTitle&returnformat=json", dataType: "json", data: { searchterm: request.term }, success: function(data){ response(data); } }) }, minLength: 3, select: function(event, ui) { $('#searchField').val(ui.item.value); $('#defaultArticleID').val(ui.item.label); } }); });    ...  
...

我的CFC:

        SELECT ID, title FROM kbArticles WHERE title LIKE              

UPDATE

在进行建议的更改时,我仍然在自动填充表单字段中没有收到任何数据。 如果我在CFADMIN控制台中启用**启用请求调试输出**,我会看到以下错误:

未捕获的TypeError:无法读取未定义的属性“文档”。

当我单击控制台输出中错误旁边的链接时,它显示的是:

 function writeToWindow( win ) { if( document.getElementById ) { // NS6 // failing on  for unescape() ?, and failing on writeCSS without unescape(), no the issue is with ns6 writing out the  tag for css // NS6 needs unescape() or else it writes 'showHide%28%27cf_debug_parameters%27,%27img_cf_debug_parameters%27%29;' for methods //win.document.write(unescape(document.getElementById("cf_debug").innerHTML)); //NS6.2 wants it escaped win.document.write(document.getElementById("cf_debug").innerHTML); } else { win.document.write(document.all['cf_debug'].innerHTML); } win.document.close(); win.focus(); }

(评论扩大……)

正如这里提到的 ,错误意味着代码期望解析的JSON 对象 ,但是传递了一个简单的字符串 。 jQuery没有将您的cfc响应字符串解析为JSON对象。 相反,它只是将普通字符串传递给response()函数,这会导致错误,因为该函数需要一个数组。 未自动解析响应的原因是datatype具有错误的大小写。 它应该是:

  dataType: "json" // Note, upper case "T" 

顺便说一句,不要忘记var/local scope所有函数局部变量,包括查询名称。

更新:

我认为这里更简单的方法是将cffunction参数名称更改为term然后使用URL作为源。 此外,由于您没有使用cfform的任何额外function,因此也可以切换到普通的html元素。

  ...