I'm attempting to display an 'alert' box containing text retrieved from a JSON file. However, I'm facing issues in fetching data from the JSON file and the alert box is not being displayed.
var thebook = JSON.parse(book);
function showAlert() {
alert(thebook[0].word);
}
<head>
<script type="text/javascript" src="book.json"></script>
</head>
<body>
<button onclick="showAlert()">show alert</button>
</body>
Here goes an illustration JSON file
[
{
"word" : "cuiller",
"page" : 23
},
{
"word" : "arbre ",
"page" : 245
}
]