I did 3 things to make your code work:
1: I added an id to the
form tag and changed your click handler to
[YOUR CODE HERE]
This stops the page from reloading every time you try to send your form.
2: I changed your wikipedia url to this:
let url = "https://en.wikipedia.org/w/api.php?action=query&list=search&format=json&srprop=snippet&srsearch=" + searchTerm;
I used this in mine and copy/pasted it while debugging.
Quick tip: If you can’t past that url into the browser search bar and get your desired data back, it isn’t working. That’s how I usually start when working with APIs… get the right response, then build around it.
3: Notice that there’s no callback on that url? I removed it in favour of letting jQuery do the work. In your ajax call, I changed datatype to
dataType: "jsonp",. This automatically adds the callback for you so you don’t have to worry about it.
And the rest is for you to try.
You’ll have to look through the response and reformat your
success call to get valid output.
Let us know if you have other questions.