我在CFC文件中有一个函数,它将从.cfm文件中调用,如下所示
<cffunction name="cftest" access="public" returntype="query" output="true" hint="Function returns Records">
<cfquery name="qryTest" datasource="DBTest">
select * from emp_tab;
</cfquery>
<cfreturn selectRecordsResultSet />
</cffunction>
Run Code Online (Sandbox Code Playgroud)
如何使用cftry处理数据库异常?因为这是返回Query,是否有可能捕获数据库异常并将详细信息传递到调用它的其他页面?
谢谢
嘿伙计们,我有一个处理动态变量名称的问题.发生的事情是我有一个CFC,它使用表中的一些数据为我构建表单的一部分.然后cfc将表单的代码作为字符串发送回页面.我需要为这些表单字段赋值,以便人们不会覆盖数据.我在cfc中的函数中提取数据.所以我试图将这个动态变量抛入字符串中,这对我来说很糟糕.我一直在说错误
A CFML variable name cannot end with a "." character.
这是我正在使用的代码,它给了我错误.我对编程没有太多经验我没有这么做太久.所以任何输入都会很棒.
<!--- ================================================================== --->
Run Code Online (Sandbox Code Playgroud)
<cfargument name="catFormQuery" type="query" required="yes">
<cfargument name="listingID" required="yes">
<cfset var getListingInformation = "">
<cfset var returnVar = "">
<cfset var fieldValue = "">
<cfset var catNameNoSpace = "">
<!--- get the listing Information --->
<cfquery name="getListingInformation" datasource="backEndDSN">
Select * from listings
where listingID = #arguments.listingID#
</cfquery>
<cfoutput query="arguments.catFormQuery">
<!---====================--->
<!--- Set catNameNoSpace --->
<!---====================--->
<cfset catNameNoSpace = replaceNoCase(arguments.catFormQuery.catName, " ", "_")>
<!---==========--->
<!--- for text ---> …Run Code Online (Sandbox Code Playgroud) 如何在不使用cfinvoke的情况下在CFC上调用静态方法?我知道我可以这样做:
<cfinvoke component="MyComponent" method="myStaticMethod' arg1="blah" returnvariable=myReturnVar>
Run Code Online (Sandbox Code Playgroud)
我希望能够以与UDF相同的方式调用此方法:
<cfset myReturnVar = MyComponent.myStaticMethod(blah)>
Run Code Online (Sandbox Code Playgroud)
但是,这不起作用.有语法,我搞砸了或者这是不可能的?
我正在做一个ajax帖子,通过AJAX向远程CFC提交用户评论.代码在所有时间都可以正常工作,除非注释字符长度达到约7300个字符.然后,好像CFC没有做任何事情.
在Firebug中,我可以看到,对于提交的所有评论<7300个字符,响应恢复正常,但是,对于> 7300个字符的数据包,此响应为空.
所以,我自然地在被调用的远程cfc方法中添加了一些简单的日志记录.我删除了所有代码,只是做了一些简单的日志记录,甚至没有记录,因为没有记录.从评论中删除一些字符并重新提交,然后再次运行.
所以有些事情让我相信,对于发送的大于7300个字符的大包,CFC会以某种方式拒绝请求.这可能吗?可能是什么导致了这个?我查看了管理员,但没有看到任何与此相关的设置.
任何帮助,将不胜感激.谢谢.
以下是CFC的代码.我发现提交任何jquery/ajax javascript代码是不必要的,因为它肯定有效,这个问题与请求的大小有关,但如果你觉得它可能会有所帮助,请告诉我,我也会发布它.
CFC被称为:
<cffunction name="callFunction" access="remote" returntype="any" output="false">
<cfargument name="cfc" type="string" required="yes" hint="The path or alias for the cfc to call" />
<cfargument name="functionName" type="string" required="yes" hint="The function name within the requested cfc to call" />
<cfargument name="returnFormat" type="string" default="json" hint="The format of the repsonse: xml, json, wsdl, etc." />
<cfargument name="jsonData" type="string" required="false" />
<cfargument name="isLoginRequired" type="boolean" default="true" />
<cfset application.Security.LogItem("CFC: #arguments.cfc#", false, false) />
<cfset application.Security.LogItem(arguments.jsonData, false, false) />
<cfset var sResponse …Run Code Online (Sandbox Code Playgroud) 我很喜欢Coldfusion,并通过网址通过网络传递表格中的变量.我无法绕过这个移动设备.我正在开发一个从我的服务器上的数据库中提取的应用程序.我现在有2次调用服务器只是在没有任何"where"语句的情况下提取数据,而且它们工作得很好.我想添加一个搜索输入,该输入将包含用户在框中输入的内容,以便在我的.cfc中查询.不确定如何将电话表格中的数据传递到我服务器上的cfc.
这是搜索按钮代码......
<form action="searchresult.html" method="post" data-transition="none">
<input type="search" name="mySearch"
id="mySearch" value="" data-mini="true" data-theme="b" />
</form>
Run Code Online (Sandbox Code Playgroud)
这是我在XCode中的脚本代码,应该在提交搜索时运行...(我不知道将任何变量传递到cfc的位置.可以在URL中传递吗?)
$("#resultPage").live("pageshow", function() {
console.log("Getting remote list" + event.notification);
$.mobile.showPageLoadingMsg();
$.get("http://www.mywebsite.com/jquery/ryprad.cfc?
method=getsearch&returnformat=json",
{},
function(res) {
$.mobile.hidePageLoadingMsg();
var s = "";
for(var i=0; i<res.length; i++) {
s+= "<li><a name=" + res[i].id + " + href='"
+ res[i].showlink + "'>"
+ res[i].date + "<br/>" + res[i].name + "<br/>"
+ res[i].description + "</a></li>";
}
$("#resultList").html(s);
$("#resultList").listview("refresh");
},
"json"
);
});
Run Code Online (Sandbox Code Playgroud)
这是我在服务器上的cfc ......
component {
remote array function getsearch() …Run Code Online (Sandbox Code Playgroud) 任何人都知道cfincludeCFC中许多功能的.cfm 有多贵?
<cfcomponent>
<cfinclude template="functions.cfm">
Run Code Online (Sandbox Code Playgroud)
或者如果我将函数直接附加到其This范围内,它会更快吗?(func1,func2将是singleton Factory对象的函数).
<cffunction name="createX">
<cfset x = new X()>
<cfset x.func1 = func1>
<cfset x.func2 = func2>
Run Code Online (Sandbox Code Playgroud)
哪一个在性能和内存使用方面更有效?
实际上,cfinclude效率如何?代码是否会在每个包含上编译?
我目前正在尝试使用cfc文件中的函数上传文件.当我<cffile action="upload">在同一页面上调用时,我可以让代码工作.但是,我想学习如何从cfc文件中的函数调用它.我相信我传递给<cffile>标签属性的参数存在问题,但我不确定.
这是我的HTML表单:
<form action="confirm.cfm" method="POST" enctype="multipart/form-data">
First Name: <input type="text" name="FNAME" size="25" /> <br />
Last Name: <input type="text" name="LNAME" size="30" /> <br />
Upload Attachment File Here: <input type="file" name="fileUpload"
id="fileUpload" size="30"
onchange="PassFileName()" /> <br />
<input type="hidden" name="fileName" id="fileName" /> <br />
<input type="submit" value="submit" />
<input type="reset" name="Reset Form" />
<div id="filenamesection">
</div>
</form>
Run Code Online (Sandbox Code Playgroud)
以下是表单提交到confirm.cfm页面的代码
<cfif isDefined("Form.fileUpload")>
<cfinvoke component="FileUploadExample"
method="UploadFile"
fileToUpload="#Form.fileUpload#"
sizeMax="50"
returnvariable="FileNameReturn">
<cfelse>
<cflocation url="index.cfm">
</cfif>
<h1> Thank for filling out …Run Code Online (Sandbox Code Playgroud) 假设我有一个项目,我在该项目中有几个CFC.为了这个例子,我有一个调试功能general.cfc,我想使用该功能,mandrill.cfc而不必将代码复制并粘贴到后面的cfc中.我已经google了这个,直到我不再谷歌了,我知道我需要在这里发布.
有人想带我去学校吗?
我有一个ColdFusion函数,用于检查表中是否存在记录,如果存在,则返回找到的行的数据.但是,如果记录不存在,我想让它调用我编写的JavaScript函数,并使用从JS函数返回的值继续处理CF函数.我知道CF是用Java编写的,所以我希望有一些东西可以执行这个任务.
基本上,从CF页面,步骤将是......
有任何想法吗?感谢您的任何帮助!
我这里有一个奇怪的问题.我正在使用jquery调用CFC并返回一个字符串.然后我尝试使用该字符串填充表单字段.出于某种原因,我的回复是包含HTML代码以及查询结果.
以下是JSON响应在控制台中的显示方式:
> Gary Turner check_out.cfm:146 Successfully ran JSON, now changing
> input value check_out.cfm:149 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML
> 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <head>
> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
>
> </head> <body>
>
>
>
>
>
> </body>
> 274.00
Run Code Online (Sandbox Code Playgroud)
这是我的JQUERY:
<!---Populate Grand Total --->
<script>
function PopulateGrandTotal(){
// Populate the customer alert DIV based on the customer selection
console.log( $("#customer_checkout>option:selected").attr("Value") );
$.ajax({
url:'cfcs/grand_totalDIV.cfc?method=getTotal&returnformat=json',
//dataType: 'text',
data: { customer_checkout: $("#customer_checkout>option:selected").attr("Value") },
success: function(response) {
console.log('Successfully ran …Run Code Online (Sandbox Code Playgroud) cfc ×10
coldfusion ×10
jquery ×3
cffunction ×2
ajax ×1
cffile ×1
cfml ×1
cordova ×1
dynamic ×1
file-upload ×1
function ×1
javascript ×1
railo ×1
search ×1
variables ×1