I've been trying to figure this thing out for a while now.
The users.json file I'm using is located in "JSON" folder right next to the rest of the files. alert("Before")
is working but I can't get the alert("After")
to work :/
If anyone could help me I'd be grateful for life.
main.js
$(document).ready(readJSONFile);
function readJSONFile() {
alert("Before");
$.getJSON("JSON/users.json", function(data){
alert("After");
let options ='';
for(let i= 0; i<data.length;i++){
options += `<option value="${data[i].firstName}">${data[i].firstName}</option>`;
}
$('#users').html(options);
});
}
users.json
[
{
"firstName": "John",
"lastName": "Doe",
"address": "Del Mar"
},
{
"firstName": "Jonah",
"lastName": "Hill",
"address": "Jerusalem"
},
{
"firstName": "James",
"lastName": "Bond",
"address": "San Jose"
}
]