Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
428 views
in Technique[技术] by (71.8m points)

javascript - I'm trying to get data from meta weather api, but its not letting me

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It's possible the CORS workaround service you're using is unavailable, either due to a heavy traffic load or other reasons.

Thankfully, it's really, really easy to set up your own personal proxy using heroku.

Follow the directions in the first response of this thread: cors-anywhere.herokuapp.com not working (503). What else can I try?

Hope this helps.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...