从.txt文件加载数组 [英] Loading an array from .txt file

查看:68
本文介绍了从.txt文件加载数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从.txt文件加载数组.它几乎没有用逗号(,)分隔的字符串.

I need to load an array from a .txt file. It has few strings separated by commas (,).

到目前为止,我发现了.

So far I have found this.

那个家伙用.split函数将其拆分,但我遇到了问题.他使用输入来上传文件,但是,我需要将文件链接到HTML,然后将其拆分为数组并使用它.

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.

推荐答案

只需确保可通过同一域上的HTTP请求访问该文本文件,并且可以正常阅读.这是一个文本文件位于webroot中的示例.

Just 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);
        });
    });

这篇关于从.txt文件加载数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆