Skip to content Skip to sidebar Skip to footer

Reading .txt File Into Array Javascript/jquery

I am trying to read a file (stored on the web server) into an array. When I print the array I currently get 'undefined'. Here is the code im using: var cardRules = new Array; $

Solution 1:

The 'cardRules' variable never gets populated with the array data. Instead of var array = data.split('\n'); just use cardRules = data.split('\n');

Solution 2:

var cardRules = newArray();
    $.get('UserFile.txt', function(data){
            cardRules = data.split('\n');
            console.log(cardRules);
        });

Solution 3:

Try full url instead of just relative linking

http://yoursite.com/yourfilelocation/yourfile.txt

$.get('http://yoursite.com/yourfilelocation/yourfile.txt', function(data){ var cardRules = data.split('\n'); console.log(cardRules); });

Post a Comment for "Reading .txt File Into Array Javascript/jquery"