I have this function called getQuotes(), and a console.log() at the end of it that shows the correct value of currentQuote.
function getQuote() {
$.ajax({
headers: {
"X-Mashape-Key": "xxx",
Accept: "application/json",
"Content-Type": "application/x-www-form-urlencoded"
},
url: 'https://andruxnet-random-famous-quotes.p.mashape.com/?cat=movies',
success: function(response) {
var r = JSON.parse(response);
currentQuote = r.quote;
currentAuthor = r.author;
console.log(currentQuote);
}
});
};
The point is: when I call getFunction() (like code below), then show a console.log of my variable currentQuote, it is not receiving the correct value, it still an empty string as declarated. What am I doing wrong ?
$(document).ready(function() {
var currentQuote='';
var currentAuthor='';
getQuote();
console.log(currentQuote);
});