I am using ajax to call a query but am trying to return a table. I have been able to get the hardcode version to return text into a textbox but I am trying to return it back as a table. Any help with this would be greatly appreciated.
AJAX Call
$.ajax({
url: "proxy/TomorrowsDate.cfm",
type: "post",
dataType: "json",
data: {date: Tmrwdate },
success: function (data) {
console.log(data);
console.log( $('#DueTmrw'));
$('#DueTmrw').val(data.TEXT);
},
error: function (xhr, textStatus, errorThrown) {
console.log(errorThrown);
}
proxy/TomorrowsDate.cfm
<cfset result = {} />
<cftry>
<cfset session.dealerwork.tomorrowsdate = form.date >
<cfset result.date = form.date/>
<cfquery name="tomorrowTextArea">
SELECT dbo.Dealer_Track_Work.id, dbo.Dealer_Track_Work.dealerID, dbo.Dealer_Track_Work.Date_Received, dbo.Dealer_Track_Work.op_id, dbo.Dealer_Track_Work.Date_Due,
dbo.Dealer_Track_Work.Date_Complete, dbo.Dealer_Track_Work.Completed_Late, dbo.Dealer_Track_Work.Closed_by, dbo.Dealer_Track_Work.Rmks, dbo.Dealer_Track_Work.Processing_Location,
dbo.Dealer_Track_Work.Item_Count, dbo.Dealer_Track_Dealers.id, dbo.Dealer_Track_Dealers.Name
FROM dbo.Dealer_Track_Work, dbo.Dealer_Track_Dealers
WHERE dbo.Dealer_Track_Work.dealerID = dbo.Dealer_Track_Dealers.id
AND Date_Complete IS NULL
AND Date_Due = <cfqueryparam value="#session.dealerwork.tomorrowsdate#" />
AND Date_Complete IS NULL
</cfquery>
<cfset result.text = ''>
<cfoutput query="tomorrowTextArea">
<cfset result.text = result.text & "<tr>
<td>#id#</td>
<td>#tomorrowTextArea.name#</td>
<td>#Item_Count# ITEMS</td>
</tr>" />
</cfoutput>
<cfcatch type="any">
<cfset result.error = CFCATCH.message >
<cfset result.detail = CFCATCH.detail >
</cfcatch>
</cftry>
<cfoutput>#SerializeJSON(result)#</cfoutput>
This is how I try to show the information back on the page: <span id="DueTmrw" name="DueTmrw"></span>
(this does not show anything) if I use <textarea type="text" name="DueTmrw" id="DueTmrw" class="form-control" rows="7"></textarea>
it shows the right results but just as html text not as the actual table. How do I display those rows as a table passing through ajax?
All the things I have tried:
<tbody>
<span id="DueTmrw" name="DueTmrw"></span>
<textarea type="text" name="DueTmrw" id="DueTmrw" class="form-control" rows="7"></textarea>
<!---<cfoutput query="tomorrowTextArea">
<tr>
<td>#id#</td>
<td>#tomorrowTextArea.name#</td>
<td>#Item_Count# ITEMS</td>
</tr>
</cfoutput>--->
</tbody>
Also tried doing something like this: $("DueTmrw > tbody").append('<tr><td>my data</td><td>more data</td></tr>');