Last active
December 30, 2021 22:53
-
-
Save koolamusic/168113bb27da00e2d394811edec845a9 to your computer and use it in GitHub Desktop.
Read File from browser using XMLHttpRequest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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