14.06.2024, 08:25
I have one json-file and one html-file
C:/Users/usr/Test.json
and
C:/Users/usr/Test.html
. The entire website is used only local on my computer. Test.html is written once, Test.json is constantly overwritten. Test.json is essentially a table: "{[{"key1": "value1"}, {"key2": "value2"}]}".
I now need the Test.html to read in that Test.json.
I used following code, which does not work.
The html-file
<html>
<head>
<script type="text/javascript">
fetch('./Test.json')
.then((response) => response.json())
.then((json) => console.log(json));
</script>
</head>
<body>
<table id= "userdata" border="0">
<thead>
<th>First Name</th>
<th>Last Name</th>
<th>Email Address</th>
<th>City</th>
</thead>
<tbody>
</tbody>
</table>
</body>
<script>
</script>
</html>
The json-file
[
{"firstName": "Test2", "lastName": "Test1", "job": "Test2", "roll": "Haha"},
{"firstName": "Test2", "lastName": "Test1", "job": "Test2", "roll": "Haha"}
]
How to fix that?
C:/Users/usr/Test.json
and
C:/Users/usr/Test.html
. The entire website is used only local on my computer. Test.html is written once, Test.json is constantly overwritten. Test.json is essentially a table: "{[{"key1": "value1"}, {"key2": "value2"}]}".
I now need the Test.html to read in that Test.json.
I used following code, which does not work.
The html-file
<html>
<head>
<script type="text/javascript">
fetch('./Test.json')
.then((response) => response.json())
.then((json) => console.log(json));
</script>
</head>
<body>
<table id= "userdata" border="0">
<thead>
<th>First Name</th>
<th>Last Name</th>
<th>Email Address</th>
<th>City</th>
</thead>
<tbody>
</tbody>
</table>
</body>
<script>
</script>
</html>
The json-file
[
{"firstName": "Test2", "lastName": "Test1", "job": "Test2", "roll": "Haha"},
{"firstName": "Test2", "lastName": "Test1", "job": "Test2", "roll": "Haha"}
]
How to fix that?