我研究的每個教程和示例都足以讓我感到非常沮喪。我有一個使用Twitter Bootstrap和jQuery的Coldfusion頁面。我需要一個自動填充功能列出學校。這應該很容易。我根本沒有迴應。沒有錯誤(我可以使用開發工具找到)。使用Coldfusion遠程數據源的jQuery自動完成功能
經過這麼多的嘗試,這可能有點混亂。 IE瀏覽器;我不知道source: '/assets/cf/fetchColleges.cfm'
和ajax調用之間的區別。我認爲源是本地/客戶端數據源。
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>
是的,我非常想出「源」的問題。但是,使用你的代碼和我的原始代碼,當我鍵入CollegeName元素時,沒有任何證據表明發生了任何事情。我設置了斷點,並且沒有在開發工具的「網絡」選項卡下顯示。 – user990016
有趣。看看這個jsfiddle,它絕對有效。我開始打字,3個字符後,我得到了GradTax.cfc上的404,顯然是因爲我沒有它。 http://jsfiddle.net/sbCwb/1/ –
下面是我看到的,例如:GET http://fiddle.jshell.net/services/GradTax.cfc?method=GetSchoolsJson&returnformat=json&searchPhrase=test 404(NOT FOUND) 。錯誤也會提醒我。這是不是爲你做同樣的事情?在這種情況下,我會進行備份並說確保引用jQuery庫以及jQuery UI https://developers.google.com/speed/libraries/devguide –