I've implemented a basic Ajax function on my website, but I'm encountering a warning in the console.
The warning states:
Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience.
What exactly does this mean and how can I prevent it?
function readTextFile(file) {
var rawFile = new XMLHttpRequest();
var allText = "";
rawFile.open("GET", file, false);
rawFile.onreadystatechange = function () {
if (rawFile.readyState === 4) {
if (rawFile.status === 200 || rawFile.status == 0) {
allText = rawFile.responseText;
}
}
}
rawFile.send(null);
return allText;
}
function load() {
var allText = readTextFile('drinks.json');
var mydata = JSON.parse(allText);
var div = document.getElementById('cocktaillist');
div.innerHTML = "";
for (var i = 0; i < mydata.length; i++) {
div.innerHTML = div.innerHTML + "<p class='inner' id="+i+">"+ mydata[i].name +"</p>" + "<br>";
}
}