1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
var getTitle = function(){
var dataToSend = '?action=query'+ '&' + 'redirects=' + "" + '&' + 'list=' + "random" + '&' + 'rnnamespace=' + "0";
//We call the connect function and add two parameters (Url of Api and the callback function)
connect('https://en.wikiquote.org/w/api.php'+dataToSend, function(response){
var title = response.query.random[0].title;
//Check if the title is a string and not a numeric string like "152"
if(isNaN(title)){
console.log(title);
return title;
}
//If a numeric string reload the function
getTitle();
}, function(error){
console.log(error);
});
}; |
Partager