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

191
Visualizações
Accessing JSON data through API with js

WHY! Why is this not working. I am using the weatherbit api, and trying to simply get the uv index. Mind you, in a browser the proper link displays all the information but I can not get it to work through js, putting it through to a div. I replaced the actual request data with (nameOfData) for privacy, I assure you that there is no problem with the parameters specific.

$getJSON('https://api.weatherbit.io/v2.0/current?lat=(Lat)&lon=(Lon)&key=(Key)', function(data) {
    // JSON result in `data` variable
    $(".UV").html(data.data[1].uv);
});

Please help.

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

0

It is failing because you need an API key. Using the URL in the address bar of a browser does not have that restriction.

Sometimes a workaround in this case is to use a proxy on a server. Your code queries the server, and the server mimics a browser. It depends on the web service how you will fare.

about 4 years ago · Juan Pablo Isaza Relatório

0

I got it working with async, somehow.


async function getData(){
let response = await fetch(weatherbitApi);
let data = await response.json()
return data;
}
getData().then (data =>
console.log(data.data[0]));

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