I'm using jQuery in a discord Javascript bot and at some point, I'm fetching data from the web to build a string made of the retrieved data.
Here what it looks like:
var jsonFinal = '';
var oembed_url = 'http://backend.deviantart.com/oembed?url=http%3A%2F%2Ffav.me%2Fd2enxz7&format=jsonp&callback=?';
$.getJSON(oembed_url, function(data) {
jsonFinal = "("+data.author_name+")\n"+data.url;
console.log(jsonFinal);
});
console.log(jsonFinal):
As you can see, the var jsonFinal
which is supposed to contain all the data at the end, is initialized blank.
But what happens in fact is that the jsonFinal DOES contain the desired information at the first console.log
(inside the function), but becomes null again at the second console.log
(it displays nothing).
That mean either the variable jsonFinal is wiped between the two console.log, or these are two distinct variables with the same names: but I fail to get the info from jsonFinal
out the function .getJson
.
How can I do?