0

I want to read a local file with javascript. I have the following function

$(function() {
        console.log("antes de readTextFile");
        readTextFile("file:///D:/carlota/eusruveyadmin/manuales/ficheropprueba.txt")

    });

    function readTextFile(file)
    {
        console.log("readFile principio");
        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;
                    console.log("readFile fichero ",allText);
                }
            }
        }
        rawFile.send(null);
    }

In the console browser I have the following message "denied access"

enter image description here

I checked in the browser my file and I can see the file

enter image description here

How do I have to write the path of file?

1 Answer 1

3

If you're using IE you need to set Settings/Tools->Internet Options->Security->Custom Level and change security settings under "Miscellaneous" set "Access data sources across domains" to Enable.

But it won't work for the users of your app, if they're using IE and don't have the same setting

Not the answer you're looking for? Browse other questions tagged or ask your own question.