I would like to read a text file and get its content to a variable and use that variable everywhere.
var latest_date = "";
$.get('/data/latest_data.txt', function(data) {
latest_date = data; // eg "20180102"
}, 'text');
// and lots of similar functions like this
$(function() {
$.getJSON('../data/' + latest_date + '/overview.json', function(data){
$('#overview').DataTable(data);
});
});
However, other functions will run before latest_date
variable gets its correct value. How can I make sure the $.get
function runs before anything else?
It's similar to this question How should I call 3 functions in order to execute them one after the other? But I have loads of functions. I can't put all of them as the callback of the initial function. I'm also reluctant to add timeOut to all my functions. Is there a better way?