I'm trying to get data from meta weather API. due to CORS issues, I am using this proxy thing called "crossorigin.me". still, its not letting me get the data. I even included "mode: 'no-cors" after many suggested to do so.
<!DOCTYPE html>
<html>
<head>
<title> Fetch Promise </title>
</head>
<body>
<script>
function getWeather(woeid){
fetch(`https://crossorigin.me/https://www.metaweather.com/api/location/${woeid}/`,{mode: 'no-cors'})
//fetch always returns a promise
.then(data => {
console.log(data)
return data.json()
// json also returns a promise so we handle that by chaining
})
.then(result => {
const today = result.consolidated_weather[0]
console.log(`temperature in ${result.title} stay between ${today.min_temp} and ${today.max_temp}`)
})
.catch(error => console.log(error))
}
getWeather(2487956)
</script>
</body>
</html
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…