Bri*_*man 2 coldfusion jquery cfc
我这里有一个奇怪的问题.我正在使用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 JSON, now changing input value');
$("#grand_total_due").val( response );
console.log(response);
},
error: function(response){
console.log('Error');
}
});
}
</script>
Run Code Online (Sandbox Code Playgroud)
这是我的CFC:
<cffunction name="getTotal" access="remote" returntype="string">
<cfargument name="customer_checkout" type="any" required="true">
<!--- localize function variables --->
<cfset var dataDetail = "">
<cfquery name="dataDetail" datasource="#datasource#" >
select grand_total
from service_ticket
where company_name = <cfqueryparam value="#ARGUMENTS.customer_checkout#" cfsqltype="cf_sql_varchar">
</cfquery>
<cfoutput query="dataDetail">
<cfreturn dataDetail.grand_total>
</cfoutput>
</cffunction></cfcomponent>
Run Code Online (Sandbox Code Playgroud)
这是我的表格:
<cfform id="form" name="form" method="post" action="signature_popup.cfm" >
<br><br>
<div align="center"><cfselect class="required" queryPosition="below" query="get_ticket" display="company_name" name="customer_checkout" id="customer_checkout" tabindex="0" onchange="PopulateGrandTotal();" ><option>---Make A Selection---</option></cfselect>
<br><br>
<div id="grant_totalDIV" >
<h2><label for="grand_total_due">Total Amount Due:</label><input type="text" name="grand_total_due" id="grand_total_due"> </h2>
</div>
<br>
Run Code Online (Sandbox Code Playgroud)
您应该查看Application.cfc文件 - 或Application.cfm - 它可能是设置页眉/页脚值.寻找"onrequestend()"和"Onrequest()"或"onrequeststart()" - 这可能会让你感到高兴.
您可能还有一个自定义标记类型方法 - 包装每个请求的东西.
你的returnType需要设置为json - 否则你得到"274.00"没有json包装器.
要修复HTML,您需要检查CFC,而不是运行相关功能.或者,您可以在CFC的文件夹中使用单独的Application.cfc,它们完全排除这些功能.当您直接从代码访问CFC时(例如在createobject()中),这样一个单独的Application.cfc不起作用 - 但是当它们是您的示例中的请求的基本模板时,它会进入播放状态.
请记住,您可以使用method = getTotal等从浏览器进行测试 - 无需在控制台中对此进行故障排除,直到您在浏览器中获得正确的结果.
| 归档时间: |
|
| 查看次数: |
224 次 |
| 最近记录: |