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
I want to get content of text file. In addition, how can I use in JavaScript? e.g line by line or array?
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