I need to read a text file into an array in Javascript.
1) I got this basic code off of stackoverflow:
var myArray = [];
$.get("../MyFile.txt", function(data){
myArray = data.split('\n');
});
2) The code works great when called from the original loading of a php page. 3) The code never works when the php page is called from another php page (via a window.location.href setting). The code seems to start, but I suspect, due to the asynchronous nature of javascript, it is not finished, and code execution continues. My file is a list of about 260,000 words. That may sound like a lot, but it normally seems to load in under a second. myArray needs to be populated before I can do anything valid. I tried to use asynch: false, but I am still having this problem. Thanks for any ideas... No matter how I try to outsmart this problem, like reloading or checking the size of the array, I am still confronted an array that is not populated when it needs to be.