Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

190
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda