how to load data from text file to javascript array?

前端 未结 3 1103
失恋的感觉
失恋的感觉 2020-12-10 20:49

i have an array called items=[\"apple\",\"mango\",\"cherry\"];

i wonder how i can load the array data from text file instead of declaring it?the text f

3条回答
  •  天涯浪人
    2020-12-10 21:27

    Sorry, but I don't believe it's quite that simple. Browsers restrict access to local drives (and to server drives) for security reasons.

    But one way to access the text file using jQuery would be

    jQuery.get('http://localhost/foo.txt', function(data) {
        var myvar = data;
    });
    

提交回复
热议问题