I have a simple javascript script, and I want to use a CSV file present in a remote url (for instance https://not-my-domain.com/test.csv
) in it.
I don't need to parse the CSV, just to get it as a simple string. I've tried:
function getCSV() {
var file = "https://not-my-domain.com/test.csv";
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();
alert(allText); //UNDEFINED!
return allText;
}
But somehow the allText is still undefined
after the function has terminated. If you could assist me in this little issue I'd be glad.