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

130
Visualizações
JSON value gives undefined

I have created an electron app that fetches a JSON value from https://complimentr.com/api. But, when you click the button to set the innerHTML value to the JSON value, it gives the dreaded 'undefined'.

// create a variable called url and set it to the url of the website
var url = "https://evilinsult.com/generate_insult.php?lang=en&type=json";
// create a variable called response and set it to the response of the get request
request(url, function(error, response, body){
  var data = JSON.parse(body);
  console.log(data.compliment);
  const btn = document.getElementById('button-1');

  btn.onclick = () => {
    document.body.innerHTML = data.compliment
  }
});

Is there any reason this isn't working? I am new at JavaScript so this could be an easy fix.

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

0

It should be response.compliment not data.compliment

console.log(response.compliment);

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