I'm eager to try out the Wikipedia search API in JavaScript, even though it might be simpler with jQuery. I want to make sure I understand the basics first before turning to frameworks. Below is the code I've come up with, but for some reason, I never receive the alert:
document.getElementById("go_search").addEventListener("click", () => {
let wiki = new XMLHttpRequest();
wiki.addEventListener("load", () => {
alert(wiki.responseText)
});
wiki.open("GET", "https://en.wikipedia.org/w/api.php?action=query&format=json&list=search&utf8=1&srsearch=Albert+Einstein");
wiki.send();
})
The URL used in the code searches for 'Albert Einstein' on Wikipedia as a test case. Thank you for your assistance; it's greatly appreciated!