const username = document.querySelector("span.username").textContent;
if (localStorage.getItem(username) === null) {
//user data not found, start setting
//localStorage.setItem(username, JSON.stringify(userA));
console.log("localstorage for " + username + " is not found");
$.getJSON("./php/settings.json", function(json) {
console.log(json[username]);
userA = json[username];
localStorage.setItem(username, JSON.stringify(userA));
});
}
My data is structured as follows in my /settings.json file. (by the way, console.log(json[username]);
displays the data correctly when the code snippet is copied and pasted into the developer console).
./settings.json
{"sarah":{"userCData":[{"id":"slz1","checked":"false"},{"id":"slz2",...................]}}
{"albert":{"userCData":[{"id":"slz1","checked":"false"},{"id":"slz2",...................]}}
{"sally":{"userCData":[{"id":"slz1","checked":"false"},{"id":"slz2",...................]}}
{"petey":{"userCData":[{"id":"slz1","checked":"false"},{"id":"slz2",...................]}}
{"gilbert":{"userCData":[{"id":"slz1","checked":"false"},{"id":"slz2",...................]}}
What am I missing here? The intention is to fetch from my json file if the user's data in localstorage is not found.