[Solved]Wikipedia API Problem

I am having troubles getting json back from the wikipedia api. I am using the fetch api for the request. Can someone take a look at my code and tell me what is going on?

[Solution]
Removed onsubmit=“search()” from form and made an event listener on my search button as @RandellDawson stated. For the addEventListener second parameter I used an anonymous function and it handled a preventDefault so the page wouldn’t refresh.
function(e){ e.preventDefault; search(); }

Get rid of the onsubmit=“search()” on your form element. Then in your JavaScript modify your search function by adding an event parameter and then inside the function call event.preventDefault. This will prevent the form from trying to submit to another page. Since your form did not provide an action attribute, the default action is to reload the same page. The preventDefault stops this.

To get a response back from the wiki API, you just need to add a click event handler to the button with id=“search-button” like:

document.getElementById('search-button').addEventListener("click", search);
1 Like

Thank you. The request works but the search function is saying preventDefault is undefined. What does that mean?

[Solved] I put the search function inside an anonymous function for the second param of addEventListener.