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

194
Visualizações
Write in a <p> api response

I'm trying to get a response from this api : https://spen.tk/api/v1/isScamLink

The api response looks like this :

{"status":200,"result":true,"linkFound":""}

I want to get the result part into a var and use it in a paragraph in HTML.

This is my js code in the site :

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
  $(function() {
  $.ajax({
    url: 'https://spen.tk/api/v1/isScamLink?link=' + document.getElementById("box").value,
    type: 'GET',
    dataType: 'json',
    success: function(response) {
      var result = response.data.total;
      var final = $('#result').text(result);
    }
  })
})
</script>

It sais this error : Uncaught TypeError: Cannot read properties of undefined (reading 'total')

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

0

Your response json doesn't contain the key 'data', that's why you're getting error.

about 4 years ago · Juan Pablo Isaza Relatório

0

Your data will be in response.result

  $.ajax({
    url: 'https://spen.tk/api/v1/isScamLink?link=https://google.com',
    type: 'GET',
    dataType: 'json',
    success: function(response) {
      console.log(response.result)
    }
  })
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

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