I'd like to use wikipedia search api from javascript, I know it might be easier with something like jquery but I'd like to get a good grip on the basics before using frameworks. Here is the code I wrote, but I never get 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 wikipedia adress is a search Albert Einstein, which is just to test if the code is working. Thanks for your help it is much appreciated!
loadevent, listen for theonreadystatechangeevent. The you can check thereadyStateandstatusof yourXMLHttpobject to know the status of the ajax callfetch("https://en.wikipedia.org/...").then(response => response.json()).then(res => console.log(res))