When I click a button I want to pass that button poke.pid to add that to a URL to get some info;
The button
list = list + `<a href="#listing" id="${poke.pid}"
onclick="getPo('${poke.pid}')"
class="collection-item">${poke.name}</'a>`;
The code below is what I have;
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;
}
My question is when I click the button can I pas that pid by appending it to the url in question and thus load an item from the subsequent json? If so how?
I found it:
//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');
Any one of the options above would work.