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

217
Vistas
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 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