Estoy tratando de crear un motor de búsqueda usando XMLHttpRequest para extraer datos de un archivo JSON. Cuando el usuario final escribe un nombre, aparece el nombre de un héroe. Una vez que el usuario encuentra a su superhéroe, hace clic en el nombre y los datos del héroe se mostrarán en una nueva pestaña. Cuando pruebo mi sitio no recibo ningún error. Creo que se debe realizar una llamada a la base de datos cuando se carga la página, pero no estoy seguro. Mi JSFiddle y el código están a continuación.
https://jsfiddle.net/pcoding159/7s9ymf5L/
HTML
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <title>Search</title> </head> <body> <script src = "script.js"></script> </body> </html>JAVASCRIPT
// xmlRequest xhrRequest.addEventListener('DOMContentLoaded', function (event){ xhrRequest.open('GET','https://akabab.github.io/superhero-api/api/all.json'+val); xhrRequest.send(); console.log(xhrRequest) }); } // handling enter key event document.getElementById('hero-name').addEventListener('keydown',function(event){ if(event.key.code==13){ if(heroId==0){ alert('No hero found! Try selecting the hero from the list'); }else{ showHero(); } } });Gracias