Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

201
Visualizações
How do I get the id of a button to be passed to and appended to a URL thus loading from a JSON?

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?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

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.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda