I am trying to populate a DIV with coldfusion query data based on a selection from a drop-down lsit. I am currently doing it by binding a CFDIV to a CFM action page but I am trying to do it via a pure JAVASCRIP solution instead.
So via an AJAX call to a CFC I am recieving the following error: 500 (Error Executing Database Query.)
The details of the error are:
Error Executing Database Query. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE customer_id = 211 AND alert_status = 'on'' at line 4
It doesn't like my last query in my CFC for some reason yet that query work in my other code where I bind to a CFDIV.
Here is my AJAX:
<script>
function PopulateCustomerAlertDIV(){
// Populate the customer alert DIV based on the customer selection
$.ajax({
url:'cfcs/customerAlertDIV.cfc?method=getAlert&returnformat=json',
data: { company_name: $("##company_name>option:selected").attr("Value") },
success: function(response) {
$("##CustomerAlertDIV").val( response );
}
});
}
</script>
Here is my DIV that I want to dynamically populate:
<div id="CustomerAlertDIV" style="display: block;"></div>
Here is my SelectBox:
<cfselect queryPosition="below" name="company_name" id="company_name" value="company_name" bind="cfc:cfcs.taxdata.getData()" bindonload="true" tabindex="0" onchange="PopulateCustomerAlertDIV();" >
<option>---Make A Selection---</option>
</cfselect>
Here is my CFC:
<cffunction name="getAlert" access="remote" returnType="string">
<cfargument name="company_name" type="any" required="true">
<!--- localize function variables --->
<cfset var dataDetail = "">
<cfquery name="getID" datasource="#datasource#" >
select customer_id
from customer_table
where company_name = <cfqueryparam value="#ARGUMENTS.company_name#" cfsqltype="cf_sql_varchar">
</cfquery>
<cfquery name="dataDetail" datasource="#datasource#">
SELECT ID, alert, alert_priority
FROM customer_alerts
<!--- adjust cfsqltype if needed --->
WHERE WHERE customer_id = #getID.customer_id# AND alert_status = 'on'
</cfquery>
<cfreturn dataDetail.alert>
</cffunction></cfcomponent>