I ran into a roadblock when developing my website. I need it to pull a text file in the same directory and return each line as an array.
So I did my research and came up with a function that seemed simple enough. However when I alert(theArray); it returns as undefined. What am I doing wrong?
function pullText(x)
{
var fullText = [];
fileReturn=new XMLHttpRequest();
fileReturn.onreadystatechange=function()
{
if (fileReturn.readyState==4 && fileReturn.status==200)
{
entireTextFile = fileReturn.responseText;
// alert(entireTextFile); works as expected here
lines = fileReturn.responseText.split("\n");
// alert(lines); works as expected here
fullText = lines;
}
}
// alert(fullText); does not work.
fileReturn.open("GET",x,true);
fileReturn.send();
return fullText;
}