Bri*_*Bri 3 coldfusion jquery jquery-plugins
UPDATE2:
这里包含了jQuery(以及当前的jQuery):
<script type="text/javascript" src="/honors/thesis_submission/js/jquery-ui.js"></script>
Run Code Online (Sandbox Code Playgroud)
$(document).ready(function() {
$('#advisor_email').autocomplete({source: "/honors/thesis_submission/cfc/advisors.cfc?method=advisorLookUp&returnFormat=json", minLength: 2});
});
Run Code Online (Sandbox Code Playgroud)
更新方法:
<cffunction name="advisorLookUp" access="remote" output = "false" returntype="any">
<cfargument name="term" type="string" required="no">
<cfset var advisorLookUp = "">
<cfset var a = []>
<cfset var s = {}>
<cfquery name = "advisorLookUp" datasource = "#dsn#">
SELECT id, email
FROM budPerson
WHERE email like <cfqueryparam cfsqltype="cf_sql_varchar" value = "#trim(arguments.term)#%">
</cfquery>
<cfloop query = "advisorLookUp">
<cfset s = StructNew()>
<cfset s["id"] = id>
<cfset s["label"] = email>
<cfset s["value"] = email>
<cfset arrayAppend(a,s)>
</cfloop>
<cfreturn a>
</cffunction>
Run Code Online (Sandbox Code Playgroud)
形成:
<cfform enctype="multipart/form-data" name = "coversheet">
<!-- other fields excluded -->
<input name="advisor_email" type="text" id="advisor_email" size="40">
<!-- other fields excluded -->
</cfform>
Run Code Online (Sandbox Code Playgroud)
再次注意......我能够通过将我方法中的SAME代码放在常规的cfm页面上并且只是cfoutputing来实现这一点......很奇怪?:\我想通过我的cfc中的远程方法来实现它.
更新:
切换到jQuery UI并更新我的代码以匹配它.我仍然没有从我的方法远程获得响应.
-
我正在尝试设置一个jQuery Autocomplete插件(具体来说:http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/).
我只是在自动完成中使用coldfusion构建,但它不适合我(给我一个错误,显然我无能为力.)
无论如何,我的cfc中的远程方法不会给我回复.Firebug表现得像是好事和东西,但实际上并没有给我回报.
这是我的功能:
<cffunction name="advisorLookUp" access="remote" returntype="any">
<cfargument name="q" type="string" required="yes">
<cfset var advisorLookUp = "">
<cfset var arr = "">
<cfquery name = "advisorLookUp" datasource = "#dsn#">
SELECT id, email
FROM budPerson
WHERE email like <cfqueryparam cfsqltype="cf_sql_varchar" value = "#trim(arguments.q)#%">
</cfquery>
<cfsavecontent variable="arr">
<cfoutput query = "advisorLookUp">
#advisorLookUp.email# | #advisorLookUp.id#
</cfoutput>
</cfsavecontent>
<cfreturn arr>
</cffunction>
Run Code Online (Sandbox Code Playgroud)
我按照插件的方式格式化返回.好吧,我觉得这并不重要......我真的只是想知道我得到了一个回复(我现在不是这样).
这是我的jQuery调用方法:
$('#advisor_email').autocomplete(
"/honors/thesis_submission/cfc/advisors.cfc?method=advisorLookUp&returnFormat=json");
Run Code Online (Sandbox Code Playgroud)
我只是通过调用来测试没有jQuery的方法,它运行得很好.有任何想法吗?
你在运行哪个版本的ColdFusion?如果不是最新的(版本9),那么您可能需要将以下if语句添加到Application.cfc中的onRequestStart()方法,以解决onRequest()函数的存在与远程调用混淆的错误:
<cffunction name="onRequestStart" returnType="boolean" output="false">
<cfargument name="thePage" type="string" required="true">
<!--- Other code in your onRequestStart method --->
<!--- Add the following to the end of your onRequestStart method --->
<cfif ListLast( arguments.thePage,"." ) IS "cfc">
<cfset StructDelete( this, "onRequest" )>
<cfset StructDelete( variables,"onRequest" )>
</cfif>
<cfreturn true>
</cffunction>
Run Code Online (Sandbox Code Playgroud)
这将检测请求是否为远程cfc调用并删除onRequest函数.
(注意:确保"arguments.thePage"匹配您为该参数声明的任何名称.有些人将其命名为TargetPage或类似名称.只要它与您声明的名称匹配就无关紧要.)