Skip to content

Instantly share code, notes, and snippets.

@koolamusic
Last active December 30, 2021 22:53
Show Gist options
  • Save koolamusic/168113bb27da00e2d394811edec845a9 to your computer and use it in GitHub Desktop.
Save koolamusic/168113bb27da00e2d394811edec845a9 to your computer and use it in GitHub Desktop.
Read File from browser using XMLHttpRequest
function readTextFile(file) {
var rawFile = new XMLHttpRequest();
rawFile.open("GET", file, false);
rawFile.onreadystatechange = function () {
if(rawFile.readyState === 4) {
if(rawFile.status === 200 || rawFile.status == 0) {
var allText = rawFile.responseText;
doSomethingWithTheText(allText);
}
}
}
rawFile.send(null);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment