0

Can someone tell me why my code doesn't work?

I'm trying to alert all the text of a local file on my computer using javascript.

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;
                alert(allText);
            }
        }
    }
    rawFile.send(null);
    return(allText);
}


readTextFile("C:\\Users\\exampleFile.js");
Akshay
  • 73
  • 5
  • 1
    possible duplicate of https://stackoverflow.com/questions/371875/local-file-access-with-javascript – hawkstrider Jul 31 '18 at 19:13
  • 1
    Possible duplicate of [How to read a local text file?](https://stackoverflow.com/questions/14446447/how-to-read-a-local-text-file) – Tareq Jul 31 '18 at 19:13
  • 1
    As you can see from the two comment above, this question has possibly been answered before, and is easily found on this site using Google. If you already have tried those solutions, and not found them to work for you, please write so in your question, explain what differs from those use cases, and provide some more information regarding what errors you are experiencing. On behalf of the community here at SO, I also want to apologise for the two comments above, as they are not helpful at all to new users not familiar with the preferred way of including information here on SO. – Canis Jul 31 '18 at 19:31

0 Answers0