我有一個表單設置,我從列表中選擇一個名稱,調用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 –