使用metaweather / location api时遇到问题

时间:2019-10-12 08:10:57

标签: javascript json ajax api

我遇到以下错误

crossorigin.me/:1 Failed to load resource: the server responded with a status of 522 ()
AJAX calls with FETCH and PROMISES.html:1 Access to fetch at 'https://crossorigin.me/https://www.metaweather.com/api/location/2487956/' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
AJAX calls with FETCH and PROMISES.html:18 TypeError: Failed to fetch

我试图通过crossorigin.me解决它,但是没有用

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Making AJAX calls with FETCH and PROMISES</title>
</head>
<body>
    <script>

        fetch('https://crossorigin.me/https://www.metaweather.com/api/location/2487956/')

        .then(result => {
            console.log(result);
        })
        .catch(error => {
            console.log(error);
        });

    </script>
</body>
</html>

我期望得到诺言

1 个答案:

答案 0 :(得分:0)

我正在尝试相同的api。

我发现很遗憾,该网站crossorigin.me不再维护,该域名现在已经可以出售。

好消息是还有其他方法可以完成此任务。此外,值得注意的是,在互联网上进行一些搜索之后,metaweather api本身就很难用ajax来获取。如此众多的用户为此而苦苦挣扎。因此,您可以考虑使用其他API。请参阅以下github代码供您参考,我尝试了它,只是它需要一些调整,因为它不能完全起作用:metaweather api gist