I'm still fairly new to Ajax so bear with me here.
I'm using $.get()
to retrieve and read a text file from the server. I need to store the data in a variable outside of scope so that I could use it later.
function some_func() {
var ex_var = "A";
$.get("test.txt", function(data) {
ex_var = data;
console.log(ex_var); // Works
});
console.log(ex_var); // Does not work
}
From reading this, I understand why outside of the scope doesn't work. However, it seems that would mean I would need to do everything inside the callback of the $.get()
itself, which doesn't seem appealing to do. Is there any better way of storing the data from $.get()
so that it could be used later?