Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
116
rated 0 times [  120] [ 4]  / answers: 1 / hits: 34151  / 8 Years ago, tue, july 26, 2016, 12:00:00

I want to get content of text file. In addition, how can I use in JavaScript? e.g line by line or array?


More From » javascript

 Answers
21

It seems that you target client-side .



Then if your text file is hosted under the same project where page HTML contains or import the following script :



$.get('/docs/file.txt',{},function(content){
let lines=content.split('n');

console.log(`file.txt contains ${lines.length} lines`)
console.log(`First line : ${lines[0]}`)

});


Assume that if we have the following routing rule :




  • http://localhost/ ---> /var/www/html/index.html



/docs/file.txt should follow this rule :




  • http://localhost/docs/file.txt --> /var/www/html/docs/file.txt


[#61242] Saturday, July 23, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tomas

Total Points: 165
Total Questions: 111
Total Answers: 103

Location: Maldives
Member since Tue, Dec 21, 2021
2 Years ago
tomas questions
Thu, Jan 27, 22, 00:00, 2 Years ago
Mon, May 10, 21, 00:00, 3 Years ago
Tue, Jan 5, 21, 00:00, 3 Years ago
;