How to read a text file from javascript

-1

Hi guys I would like to know how I can read a text file from javascript

    
asked by Code tutoriales 07.12.2017 в 03:58
source

1 answer

1

We must verify the status with 4 (zero)

function leeArchivo(file)
{
    var archivo = new XMLHttpRequest();
    archivo.open("GET", file, false);
    archivo.onreadystatechange = function ()
    {
        if(archivo.readyState === 4)
        {
            if(archivo.status === 200 || archivo.status == 0)
            {
                var Texto = archivo.responseText;
                alert(Texto);
            }
        }
    }
    archivo.send(null);
}

// We call the function passing as a parameter the path of the file to load link :

leeArchivo("http://web/archivo.txt");
    
answered by 07.12.2017 в 04:13