I'm trying to implement the Wikipedia Search API and write the results to the page. (They show up in the console.)
I've tried a for loop through "data.query.search.title". I tried "JSON.stringify(data, null, 2)" but that's not what I was looking for.
Here is a JSFiddle:
https://jsfiddle.net/magoo/s8t5qb3u/4/
'''function search(event) {
event.preventDefault();
var input = document.getElementById('searchInput'). value;
var searchText = input.trim().toLowerCase();
var url = "https://en.wikipedia.org/w/api.php?action=query&format=json&prop=links&list=search&srsearch=" + searchText + "&srnamespace=0&srinfo=&srprop=snippet%7Ctitlesnippet&callback=?"
$.getJSON (url, function(data) {
var output = data.query.search;
display.innerHTML = output;
console.log(output);
})}
'''
The console shows multiple objects. The page shows [Object object] repeated multiple times.
My hope is to get the title, snippet, and URL.
Hope I did this post correctly. Thanks in advance.