Reputation: 121
I've been trying to figure out the best method for retrieving data from a file and putting it in an array. The final goal is to create a dictionary for a game so that I can validate words that were submitted by a user.
Although I'm still new programming, I've done some research and it seems that .get function may allow that. Before I embark on building all of that code, I wanted to check to see if my starting logic was correct.
If I have a file called wordcheck.txt and it has thousands of words. Can I retrieve the data by
$.get(workcheck.txt, functions(words) {
var wordArray = words.split( "\n");
}
I haven't figured out where to go to from here yet, but I wanted to make sure I was understanding the beginning correctly.
Upvotes: 0
Views: 75
Reputation: 63524
1) Add quotes around the file you're trying to load.
2) You might want to define wordArray
before you do the $.get
otherwise the data won't be available outside of that anonymous function.
3) It's function
not functions
.
4) You missed a closing )
.
var wordArray;
$.get('workcheck.txt', function (words) {
wordArray = words.split('\n');
});
Upvotes: 1