I'm trying to display a json local file to a html file. Found something on the google, but it really give me headache I got the following json file:
{
"activities": [
{
"name": "C:\\Windows\\System32\\cmd.exe - python autotimer.py",
"time_entries": [
{
"days": 0,
"end_time": "2020-04-14 17:14:12",
"hours": 0,
"minutes": 0,
"seconds": 4,
"start_time": "2020-04-14 17:14:08"
},
]
},
and the following html file. My problem with this html file is the part from the bottom, don't know if that is really good or not. I deteled te html part, cuz i doesn't let me post my question.
<script>
$(document).ready(function (
$.getJSON("activities.json", function (data) {
var activities_data = '';
$.each(data, function (key, value) {
activities_data += '<tr>';
activities_data += '<td>' + value.name + '</td>'
activities_data += '<td>' + value.days + '</td>'
activities_data += '<td>' + value.end_time + '</td>'
activities_data += '<td>' + value.hours + '</td>'
activities_data += '<td>' + value.minutes + '</td>'
activities_data += '<td>' + value.seconds + '</td>'
activities_data += '<td>' + value.start_time + '</td>'
activities_data += '</tr>'
});
$('#activities_table').append(activities_data);
});
));
</script>
What I'm doing wrong? I'm a newbie to all of this.
$.getJSONand similar AJAX commands will only work in a server environment; if you open the HTML file directly in the browser you're in thefile:///environment and it won't work. Get apache2 or some other web server solution and serve the files onlocalhost.$.each(data,you need to iterate through$.each(data.activities,. Then, you can appendvalue.name,value.time_entries[0].days,value.time_entries[0].end_timeas td elements.