I need help modifying this code snippet that currently reads JSON data from a file. I have generated the JSON data from my database and would like to update the code to read it directly instead of from a file. You can refer to how the JSON is being accessed in this example. In my code snippet, you will see how the data is retrieved to populate the table.
var columns = ["username", "user_id", "address", "state", "postal_code", "phone", "email"];
var level_classes = {
"NEW": "new_client",
"RENEWAL": "renewing_client",
"CURRENT": "current_client"
};
$(document).ready(function() {
$.getJSON("obtainUsers.php", function(data) {
var $table = $('<table style="width: 100%;">');
var $tbody = $('<tbody>');
$table.append($tbody);
var $tr = null;
data.forEach(function(user, index) {
if (index % 4 === 0) {
$tr = $('<tr>');
$tbody.append($tr);
}
$td = $('<td class="' + level_classes[user.level] + '">');
columns.forEach(function(col) {
$td.append(user[col]);
$td.append($('<br>'));
});
$tr.append($td);
});
$('.runninglist').append($table);
});
});
I appreciate any guidance. Thank you!