Skip to content

Instantly share code, notes, and snippets.

@ajess33
Created Mar 21, 2018
Embed
What would you like to do?
Wikipedia Viewer json
var searchbar = document.querySelector('#searchbar');
var searchButton = document.querySelector('#search');
var results = document.querySelector('.results');
var userInput = searchbar.value;
function fetchData() {
fetch(
'https://en.wikipedia.org/w/api.php?action=query&format=json&generator=search&gsrlimit=10&prop=extracts&pilimit=max&exintro&explaintext&exsentences=2&exlimit=max&gsrsearch=' +
userInput
)
.then(response => response.json())
.then(jsonData => {
var myData = jsonData.query.pages;
console.log(myData);
for (result in myData) {
console.log(result);
}
});
}
fetchData();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment