Using fetch in an event listener?

Using fetch in an event listener?
0

#1

This fetch() api request seems to work fine, until I try and put it in a click listener, then it returns an error. Please enlighten me :slight_smile:


#2

Please post the actual code instead of screen shot and give us more details like:

  • What is the error,?
  • What do you expect it to do compared to what it does instead?

#3

I think I’ve actually just figured it out…

<input id="searchTerm" type="text" placeholder="search for character" name="searchTerm">
      <button id="search-button" type="submit">Search</button>

I had this input wrapped in a form and that was preventing the value of #searchTerm from getting sent to the variable appended to the api URL. I swear I tried to solve this problem for a long while before posting a question. As soon as I did, finally found a post with similar problem/solution.