I am trying to populate a selectlist from an AJAX call to a CFC. In my CFC, a query is run that grabs a list of "vehicles" from my DB that are marked as active. Once a selection is made from the selectlist, a set of form inputs are populated based on that selection.
I know that the data returned from my selectlist should be a list of 3 vehicles.
When I load the page, my selectlist show the following text as the three items in the list:
[object HTMLSelectElement]
[object HTMLSelectElement]
[object HTMLSelectElement]
In the Chrome Browser console, I can see the response from AJAX call to my CFC:
{ "COLUMNS":["VEHICLE_NAME"]
,"DATA": [ ["Service Truck 10"]
,["Ford Transit Connect"]
, ["Ford TransitConnect New"]
]
}
What's weird is that is shows that response for each of three rows returned from my query. What would cause that?
Here is my AJAX calls:
<!--- Retrieve list of vehicles and populate the mileage in the form--->
<script>
$(document).ready(function () {
//populate the vehicle selectlists
$.ajax({
url: 'cfcs/mileagedata.cfc?method=getData&returnformat=json',
dataType: 'json',
success: function(response){
$.each(response.DATA, function(i, row){
// get value in first column ie "description"
var description = row[0];
// append new option to list
$("#vehicle_name").append($('<option/>', {
value: vehicle_name,
text : vehicle_name
}));
});
},
error: function(msg){
console.log(msg);
}
})
//Populate the start and end odometer text boxes
$.ajax({
url:'cfcs/mileagedata.cfc?method=getDetail&returnformat=json',
data: $('#addmileage').serialize(),
success: function(response) {
$("#start_odometer").val( "worked" );
$("#end_odometer").val( "worked" );
}
});
});
</script>
Here is my CFC:
<!---Service Vehicle Slect Box --->
<cffunction name="getData" access="remote" returntype="query">
<!--- Function to get data from datasource --->
<!---Get Service Vehicles --->
<cfquery name="data" datasource="#datasource#">
select vehicle_name
from vehicles
where active = '1'
</cfquery>
<!--- Return results --->
<cfreturn data>
</cffunction>
<cffunction name="getDetail" access="remote" returnType="string">
<cfargument name="vehicle_name" type="any" required="true">
<!--- localize function variables --->
<cfset var dataDetail = "">
<cfoutput>
<cfquery name="dataDetail" datasource="#datasource#">
SELECT mileage
FROM vehicles
<!--- adjust cfsqltype if needed --->
WHERE vehicle_name = <cfqueryparam value="#ARGUMENTS.vehicle_name#" cfsqltype="cf_sql_varchar">
</cfquery>
</cfoutput>
<cfreturn dataDetail.mileage>
</cffunction>