I have this index.html
file that contains a datatable that should be populated with data from a json file in the same folder. This is the index.html
file:
<!DOCTYPE html>
<html>
<head>
<title>Display JSON File Data in Datatables | Example</title>
</head>
<body>
<table id="empTable" class="display" width="100%" cellspacing="0">
<thead>
<tr>
<th>Name</th>
<th>Designation</th>
<th>Office</th>
<th>Extension</th>
<th>Joining Date</th>
<th>Salary</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Name</th>
<th>Designation</th>
<th>Office</th>
<th>Extension</th>
<th>Joining Date</th>
<th>Salary</th>
</tr>
</tfoot>
</table>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/dt-1.10.13/datatables.min.css"/>
<script type="text/javascript" src="https://cdn.datatables.net/v/dt/dt-1.10.13/datatables.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#empTable').dataTable({
"ajax": "empdata.json",
"columns": [
{"data": "name"},
{"data": "designation"},
{"data": "office"},
{"data": "extension"},
{"data": "joining_date"},
{"data": "salary"}
]
});
});
</script>
</body>
</html>
The problem is that the json file can't be loaded and I don't know how to fix it. This is the error in the console:
jquery.min.js:4 XMLHttpRequest cannot load file:///C:/Users/user/Desktop/d/empdata.json?_=1504083178306. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.`