i´m reading a text-file with jquery/ajax and convert it via the jquery/csv plugin.
This is my code:
var gotData;
function read() {
$.get('text.txt', function(data) {
var options = {"separator" : ";"};
gotData = $.csv.toArrays(data, options);
alert(gotData); //1
}, 'text');
alert(gotData); //2
}
Why is the data shown in alert 1 but not in alert 2? As I know the definition of the variable is global and should be shown, am I right? This leads to a even bigger problem because I want to access that data from my html-page (the .js is another file). So basically i want to get the variable which holds the data from my txt-file outside this function. Hope anyone can help. For further information please comment. Thank you in Advance.
Edit: The market duplicate doesn´t help me with my next problem, that I want to use that data in another .html-file to show it on my website.