Skip to content

Instantly share code, notes, and snippets.

@fdjones
Created August 29, 2018 15:44
Show Gist options
  • Save fdjones/e9d2d7ad81de22357ede53647a34d1c3 to your computer and use it in GitHub Desktop.
Save fdjones/e9d2d7ad81de22357ede53647a34d1c3 to your computer and use it in GitHub Desktop.
const forecast = document.querySelector(".forecast");
const temperature = document.querySelector(".temperature");
const btn = document.querySelector("button");
async function getWeatherData() {
const returnData = await axios.get(
"api.openweathermap.org/data/2.5/weather?id={MyAPIKeyGoezHere}",
{
headers: {
'Access-Control-Allow-Origin': '*',
"Content-Type": "application/json"
}
}
);
return returnData.data;
}
getWeatherData().then(res => console.log("data: ", res));
btn.addEventListener("click", () => {
const result = getWeatherData().then(res => alert(JSON.stringify(res)));
forecast.innerHTML = JSON.stringify(result);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment