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

218
Visualizações
why post request is not returning the right value

I am trying to get an object and then post its temp. here i get the object by the getweather function and then i made postweather function to post date (variable i made), content (user input) and temp (temp of the object i got by api).

everything is working great but the temp is retrieved as empty object even though i console.log it and is printed as a number.

async function getWeather(url) {
  fetch(url)
    .then((res) => {
      return res.json();
    })
    .then((data) => {
      // console.log(data);
      //save temp to globall variable
      globalThis.temp = data.main.temp;
    })
    .catch((error) => console.log("error:", error));

  postWeather("/post", temp);
}

//just a fun to check on temp and is printed in numbers

function noha() {
  console.log(temp);
}

//post async
async function postWeather(url) {
  try {
    await fetch(url, {
      method: "POST",
      headers: {
        "Content-Type": "application/json"
      },
      body: JSON.stringify({
        date: newDate,
        temp,
        feelings
      })
    });
  } catch (error) {
    console.log("error post", error);
  }
}
about 4 years ago · Juan Pablo Isaza
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