trying to stuff 5 pounds of CF and Jquery and Javascript and Bootstrap
into a 2 pound bag. Autocomplete
Every tutorial and example I researched was just enough "off" of what I
need to make it very frustrating. I have a Coldfusion page that uses
Twitter Bootstrap and Jquery. I need an autocomplete function to list
schools. This should be pretty easy. I get no response at all. And there
are no errors (that I can find using dev tools). this may be somewhat of a
kludge after so many attempts. IE; I don't know the difference between
"source: '/assets/cf/fetchColleges.cfm'" and the ajax call. I think source
is a local/client data source.
HTML:
<div class="row">
<div class="span9">
<input size="34" type="text" name="CollegeName" id="CollegeName" value="" />
<div id="results"></div>
</div>
</div>
Jquery:
jQuery( document ).ready(function($) {
$("#CollegeName").autocomplete({
source: '/assets/cf/fetchColleges.cfm',
minLength: 3,
select: function(event, ui) {
$('#company_id').val(ui.item.id);
// go get the company data
$.ajax({
type: 'Get',
url:
'/services/GradTax.cfc?method=GetSchoolsJson&returnformat=json',
data: {searchPhrase: query.term},
dataType: 'json',
error: function(xhr, textStatus, errorThrown) {
// show error
alert(errorThrown)},
success: function(result) {
response(result);
}
});
}
});
});
CFC:
<cffunction name="GetSchoolsJson" access="remote" >
<cfargument name="QueryString" required="true" />
<cfquery name="QComp" datasource="#request.dsn_live#">
select name
from companies
WHERE School_Flag = 'True' AND [Name] LIKE '%#Request.QueryString#%' AND
(Status_Flag IS NULL OR Status_Flag = 'A') AND Grad_Tax_Flag = 'True'
ORDER BY [NAME] ;
</cfquery>
<cfset var comp = structNew() />
<cfoutput query="QComp">
<cfset comp["name"] = '#qcomp.name#' />
</cfoutput>
<cfreturn comp>
</cffunction>
No comments:
Post a Comment