Currently, I am working on a game feature that allows users to change their display name and then save it in a JSON file for easy access across different files and pages. I initially included an XMLHttpRequest in my code, but after stumbling upon this insightful article, I began questioning whether the use of XMLHttpRequest is actually necessary. For better context, I have attached both the JavaScript and JSON files below.
JavaScript:
var console;
let requestURL = 'displayName.json';
let request = new XMLHttpRequest();
request.open('GET', requestURL);
request.responseType = 'json';
function sendRequest() {
request.send("displayName");
}
document.getElementById('displayName');
if (displayName = "") {
displayName = 'Soldier';
}
JSON:
displayNameData {
"displayName": ""
}