I'm new to jQuery trying to pull deleted data from a ColdFusion query to show it in a text box.
I get an error in firebug when calling my CFC:
Uncaught TypeError: cannot use the 'in' operator to search for '453' in
I do not know what this can mean. I see that this is pulling data from my database, because later in my console release I see my data:
[{"value":1,"label":"Test article"}] jquery-1.10.2.js:997
Can someone help with this error?
Full HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link href="css/jquery-ui-1.10.4.custom.css" rel="stylesheet" type="text/css">
<script src="Scripts/jquery-1.10.2.js"></script>
<script src="Scripts/jquery-ui-1.10.4.custom.js"></script>
<script>
$(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);
}
});
});
</script>
</head>
<body class="oneColFixCtrHdr">
...
<div id="container">
<cfform name="doesntmatter" method="post">
<label for="searchField">Search KB Articles</label>
<cfinput type="text" id="searchField" name="searchField" size="30em;" value=""/>
<cfinput type="hidden" name="defaultArticleID" id="defaultArticleID" value="0" />
</cfform>
</div>
...
</body>
</html>
My CFC:
<cfcomponent>
<cffunction name="lookupTitle" access="remote" output="no"
hint="I return a list of titles" returnformat="JSON">
<cfargument name="searchterm" required="false" default="" />
<cfset var returnArray =ArrayNew(1)>
<cfquery name="data" datasource="#datasource#">
SELECT ID, title
FROM kbArticles
WHERE title LIKE <cfqueryparam cfsqltype="cf_sql_varchar" value="%#arguments.searchterm#%" />
</cfquery>
<cfloop query="data">
<cfset titleStruct = structNew() />
<cfset titleStruct['value'] = ID />
<cfset titleStruct['label'] = title />
<cfset arrayAppend(returnArray,titleStruct) />
</cfloop>
<cfreturn returnArray />
</cffunction>
</cfcomponent>
UPDATE
When making the proposed changes, I still do not receive data in the autocomplete form field. If I enable ** Enable output debugging request ** in CFADMIN console, I see this error:
Uncaught TypeError: Unable to read the undefined property document.
, , :
function writeToWindow( win ) {
if( document.getElementById ) { // NS6
// failing on <table ... 100%> for unescape() ?, and failing on writeCSS without unescape(), no the issue is with ns6 writing out the <link> 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();
}