Hi guys, I am new at javascript and I want to know if it is possible to load either a CSV file or TXT file into an array. Basically the file gets downloaded from the net and is actually a txt file.
e.g. (“Heading 1″,”Heading 2″,”Heading 3”,”Heading 4″…. and under that is the details “Data 1″,”Data 2″,”Data 3”,”Data 4″….)
I can easily convert this to a CSV file too.
The web page will always display the data and that is all.
At the moment I have this code in my js file which I found on the net after searching for two days, this is the only way I know of at the moment. Is this OK and how do I move it into an array.
[code] var txtFile = new XMLHttpRequest();
txtFile.open(“GET”, “file://D:/Notices/notices.txt”, true);
txtFile.onreadystatechange = function() {
if (txtFile.readyState === 4) { // Makes sure the document is ready to parse.
if (txtFile.status === 200) { // Makes sure it’s found the file.
allText = txtFile.responseText;
lines = txtFile.responseText.split(“rn”); // Will separate each line into an array
} //”rn”
}
}
Am I going about this correctly? Is there an alternative to do this? I was going to display the information in a table. Bearing in mind that this is to be diplayed on a screen for people to read in a reception area. The text file itself will not have more than 100 lines (max). I will want the information to scroll on the screen but that is another problem for another day. I just need to find a way to display this text file on screen.
Thanks.