admin管理员组文章数量:1313760
I need to load an array from a .txt file. It has few strings separated by mas (,
).
So far I have found this.
That guy splits it with .split function but I have a problem. He uses an input to upload the file, however, I need to link the file to the HTML and than split it into an array and use it.
I need to load an array from a .txt file. It has few strings separated by mas (,
).
So far I have found this.
That guy splits it with .split function but I have a problem. He uses an input to upload the file, however, I need to link the file to the HTML and than split it into an array and use it.
Share Improve this question edited May 23, 2017 at 11:43 CommunityBot 11 silver badge asked Feb 3, 2012 at 10:52 David DebnarDavid Debnar 1251 gold badge3 silver badges10 bronze badges2 Answers
Reset to default 3Just make sure the text file is accessible through an HTTP request on the same domain and you can read it fine. Here's an example where the text file is located in the webroot.
$(function(){
$.get('/whatever.txt', function(data){
var array = data.split(',');
console.log(array);
});
});
You can read html files locally since html5. Check the html5 API and some examples here. Then use Alexanders answer to parse it.
EDIT: here and here are some good and short examples on how to use it.
本文标签: javascriptLoading an array from txt fileStack Overflow
版权声明:本文标题:javascript - Loading an array from .txt file - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741957885a2407094.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论