I am using this code to get the contents of data.dat. Here are the 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
However, getData() returns an empty string. When I log this.responseText this way:
if (this.readyState == 4 && this.status == 200) {
  console.log(this.responseText);
  result = this.responseText.split(",");
}
I get ["A","B","C"]. What am I doing wrong?
 
    