admin管理员组文章数量:1355535
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;
$.get('UserFile.txt', function(data){
var array = data.split('\n');
console.log(cardRules);
});
Any help would be appreciated!
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;
$.get('UserFile.txt', function(data){
var array = data.split('\n');
console.log(cardRules);
});
Any help would be appreciated!
Share Improve this question asked Feb 19, 2013 at 23:42 spogebob92spogebob92 1,4844 gold badges23 silver badges33 bronze badges 1- 1 var array is local variable for the success callback and cardRules wasn't filled in you code – krasu Commented Feb 19, 2013 at 23:45
3 Answers
Reset to default 3The 'cardRules' variable never gets populated with the array data. Instead of
var array = data.split('\n');
just use
cardRules = data.split('\n');
var cardRules = new Array();
$.get('UserFile.txt', function(data){
cardRules = data.split('\n');
console.log(cardRules);
});
Try full url instead of just relative linking
http://yoursite./yourfilelocation/yourfile.txt
$.get('http://yoursite./yourfilelocation/yourfile.txt', function(data){
var cardRules = data.split('\n');
console.log(cardRules);
});
本文标签: Reading txt file into array JavascriptjQueryStack Overflow
版权声明:本文标题:Reading .txt file into array JavascriptjQuery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743986706a2571399.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论