我有一个表单设置,我从列表中选择一个名称,调用CFC并针对该名称运行查询。然后我从该查询中返回一美元金额。使用CFC JSON结果填充输入字段
我然后试图拿出这个美元金额并且改变一个<input>
元素的值。
我可以成功运行我的CFC并返回正确的值,但我的JQUERY不会更改我的输入字段的值。它跳过我的成功:方法和正确的我的错误:方法。
这里是我的表单代码:
<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>
<div id="grant_totalDIV" >
<input type="number" name="grand_total_due" id="grand_total_due">
</div>
这里是我的CFC:
<cffunction name="getTotal" access="remote" returntype="any">
<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 = '#customer_checkout#'
</cfquery>
<cfoutput query="dataDetail">
<cfreturn dataDetail.grand_total>
</cfoutput>
</cffunction></cfcomponent>
这里的JQuery:
<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: 'json',
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('Input value cahnged');
},
error: function(response){
console.log('Error');
}
});
}
</script>
我的JSON响应:
<!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
任何人都可以帮忙吗?
好了,我注释掉的代码的一部分,现在它运行成功:方法,因为我可以看到它记录我在那里编码的消息。但它不会改变我的输入字段的值与响应。我的代码是否正确? –
尝试登录响应安慰 – charlietfl
更新:我改变了输入字段的类型从数量到文本,现在它改变了我的价值,这一点:
274.00 –