I am trying to make a dynamic table in the success part of an AJAX call. Depending on the user’s selections, the table can have totally different field names & data (different queries) from one call to the next. I am attempting to do this using JSON data to supply the field names & data for the different scenarios.
JSON
var fields = {
"Customer Name": "cust_nm",
"Circuit ID": "ckt_id",
"Speed": "speed",
};
AJAX
success: function (data) {
for (key in fields) {
if (fields.hasOwnProperty(key)) {
var x = 'data.' + fields[key];
var row = '<tr><td>' + key + '</td><td> ' + x + '</td></tr>';
$('#circuitDetails').append(row);
}
}
}
As can be seen in the result screenshot below, it is recognizing 'data.' + fields[key]
as a string rather legitimate data definition. In this case the data returned would have had 3 fields named cust_nm, ckt_id & speed.
Suggestions on how to accomplish this would be appreciated.