how to read a file in javascript?
by Ramya[ Edit ] 2009-06-16 19:26:48
Read a file in javascript:
To read a file and store the values of a file into a variable, use the following,
var txtFile = new XMLHttpRequest();
txtFile.open("GET", "http://your domain(or)path/domains.txt", true);
txtFile.onreadystatechange = function()
{
if (txtFile.readyState === 4) // Makes sure the document is ready to parse.
{
if (txtFile.status === 200)
{
allText = txtFile.responseText;
lines = txtFile.responseText.split("\n"); // Will separate each line into an array
}
}
}