On the document ready function you are trying to write the results of get_style_guide_version(), which is running an async process
So the function completes before the async has returned so that wont work.
What you should do is have another function that is called manually that writes to the document and is called when the .done promise fires.
function get_style_guide_version() {
var jqxhr = $.getJSON( '/package.json', function() {
})
.done(function(data) {
output = data.version;
console.log(output);
write(output);
});
}
$( document ).ready(function() {
document.write(get_style_guide_version());
});
function write(val){
document.write(val);
}
or
function get_style_guide_version(done) {
var jqxhr = $.getJSON( '/package.json', function() {
})
.done(function(data) {
output = data.version;
console.log(output);
done(output);
});
}
$( document ).ready(function() {
document.write(get_style_guide_version(function(val){
document.write(val);
}));
});