I'm trying to load data from a text file on my server using the $.get() function in an external script file. My code is as follows:
/*
* Load sample date
*/
var stringData;
$.get(http://localhost/webpath/graphing/sample_data.txt, function(data){
stringData = data;
//alert(Data Loaded: + stringData);
});
//Split values of string data
var stringArray = stringData.split(,);
alert(Data Loaded: + stringData);
When I'm inside the $.get() function I can see stringData var get peopulated just fine and the call to alert confirms that it contains data from the sample text file. However, when I get outside the $.get() function, the stringData var no longer shows. I don't know enough about how the function works to know why it is not doing as I expected. All I want it to do is load the text data into a variable so I can work with it. Any help is appreciated.