1
My table is not being loaded with the data that is in my JSON file, as I have little experience do not know what is wrong.
My JSON file is in the same directory as the web page in question, this is my JSON file.
[
{
"id": "1",
"name": "wladimir bandeira",
"gender": "Male",
"designation": "Manager",
"age": "38"
},
{
"id": "1",
"name": "wladimir bandeira",
"gender": "Male",
"designation": "Manager",
"age": "38"
},
{
"id": "1",
"name": "wladimir bandeira",
"gender": "Male",
"designation": "Manager",
"age": "38"
},
{
"id": "1",
"name": "wladimir bandeira",
"gender": "Male",
"designation": "Manager",
"age": "38"
}
]
mockingTest.json
This is my HTML file;
<%@ include file="/pages/template/imports.jsp" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<div class="row">
<div class="col-md-12">
<h1>Não Conformidade</h1>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="btn-group" role="group" aria-label="...">
<button class="btn btn-primary pull-left" data-toggle="collapse" data-target="#pesquisa" aria-expanded="false" aria-controls="collapseExample"><i class="glyphicon glyphicon-search"></i> Pesquisar</button>
<c:if test="${resultPage.sizeResult != 0}">
<button type="button" class="btn btn-primary" title="Gerar PDF" onclick="gerarPdf();"><i class="glyphicon glyphicon-list"></i> Gerar PDF</button>
</c:if>
</div>
</div>
</div>
<body>
<div class="container">
<div class="table-responsive">
<table class="table table-bordered table-striped" id="employee_table">
<tr>
<th>Name</th>
<th>Address</th>
<th>Gender</th>
<th>Designation</th>
<th>Age</th>
</tr>
</table>
</div>
</div>
</body>
<script>
$( document ).ready(function() {
$.getJSON("mockingTest.json", function(data){
var employee_data = '';
$.each(data, function(key, value){
employee_data += '<tr>';
employee_data += '<td>'+value.name+'</td>';
employee_data += '<td>'+value.gender+'</td>';
employee_data += '<td>'+value.designation+'</td>';
employee_data += '</tr>';
});
$('#employee_table').append(employee_data);
});
});
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
My jquery file is version 3 jquery-3.4.1.min. js and it’s imported in the right way, the part that’s wrong is the one below;
<script>
$( document ).ready(function() {
$.getJSON("mockingTest.json", function(data){
var employee_data = '';
$.each(data, function(key, value){
employee_data += '<tr>';
employee_data += '<td>'+value.name+'</td>';
employee_data += '<td>'+value.gender+'</td>';
employee_data += '<td>'+value.designation+'</td>';
employee_data += '</tr>';
});
$('#employee_table').append(employee_data);
});
});
</script>
How to fix and JSON file information appears in the table on screen?