I am trying to output a query from a .cfm page using jquery with json format. Can someone tell me what I am dong wrong?
Edit: Answer here
Edit: Just posted my cf
./test.cfm:
#SerializeJSON(getItems)#
Here's some of my code that I've modified to match your example:
My HTML:
And my javascript, which puts the query result into the table:
$("#runQuery").click(function () {
$.ajax({
type: "GET",
url: "./test.cfm",
dataType: "json",
success: function (resp, textStatus, jqXHR) {
buildResultsTable(resp);
},
error: function (jqXHR, textStatus, errorThrown)
{
alert(errorThrown);
}
});
});
function buildResultsTable(resp)
{
var tmp_html = $(" ");
var j = 0;
$("#results").html("");
for (var i = 0; i < resp["COLUMNS"].length; i++)
{
var tmp_th = $(" ");
tmp_th.text(resp["COLUMNS"][i]);
tmp_html.append(tmp_th);
}
$("#results").append(tmp_html);
for (j = 0; j < resp["DATA"].length; j++)
{
tmp_html = $(" ");
for (var i = 0; i < resp["DATA"][j].length; i++)
{
var tmp_td = $(" ");
tmp_td.text(resp["DATA"][j][i]);
tmp_html.append(tmp_td);
}
$("#results").append(tmp_html);
}
}