Trying to retrieve the content of data.dat, I have utilized the following code. Below are the relevant files:
main.js
function getData() {
var result;
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
result = this.responseText.split(",");
}
};
xhttp.open("POST","data.dat",true);
xhttp.send();
return result;
}
data.dat
A,B,C
Despite the above script, getData()
is returning an empty string. When I examine this.responseText
using the following method:
if (this.readyState == 4 && this.status == 200) {
console.log(this.responseText);
result = this.responseText.split(",");
}
I am able to obtain ["A","B","C"]
. Where could I be making a mistake?