Cuando hago clic en un botón, quiero pasar ese botón poke.pid para agregarlo a una URL para obtener información;
El botón
list = list + `<a href="#listing" id="${poke.pid}" onclick="getPo('${poke.pid}')" class="collection-item">${poke.name}</'a>`;El siguiente código es lo que tengo;
async function getPo(url){ try { let response = await fetch(url); let result = await response.json(); displayPok(result); } catch (e) { console.log(e); } } //the URL in question getPokemon(('URL/somethinghere/').append('${poke.pid}')); function displayPok(pok){ let result = document.querySelector('#result'); let html = ' '; html = html + `<div href="#result" id="${pok.pid}" class="card col m12 l10 offset-l1" style="margin-top: 20px"> <div class="card-image" > <img class="teal" src="${pok.image}" alt="Bulbasaur Image"> </div> <div class="card-content"> <span class="card-title"><p>${pokemon.name}</p></span> <p> Type1: ${pok.type1}</p> <p> Weight: ${pok.weight}</p> <p> Height: ${pok.height}</p> <a onclick="catchPokemon(1)" id="catchBtn" style="position:absolute; right:15px; bottom:80px" class="btn-floating btn-large waves-effect waves-light red"> <span class="iconify" style="font-size:40px; margin-top:8px" data-icon="mdi-pokeball" data-inline="false"></span> </a> </div> </div>`; result.innerHTML = html; }Mi pregunta es cuando hago clic en el botón, ¿puedo pasar ese pid agregándolo a la URL en cuestión y así cargar un elemento del json posterior? ¿Si es así, cómo?
Lo encontré:
//let response = await fetch(`https://pokedextr-api.herokuapp.com/pokemon/${pid}`); //let result = await response.json(); let result = await sendRequest(`https://pokedextr-api.herokuapp.com/pokemon/${pid}`, 'GET');Cualquiera de las opciones anteriores funcionaría.