【问题标题】:I'm having trouble while using metaweather/location api我在使用 metaweather/location api 时遇到问题
【发布时间】:2020-02-09 15:01:15
【问题描述】:

我收到以下错误

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>

我期待着承诺的回应

【问题讨论】:

  • 522 是 CloudFlare 的响应,表示目标服务器(crossorigin.memetaweather.com)无法访问。
  • 有什么可能的解决办法吗?
  • 不,你无能为力,只能给他们打个电话问一下
  • 这个有没有替代的api?
  • 没有crossorigin.me 是否可以工作,因为这是有问题的那个?

标签: javascript json ajax api


【解决方案1】:

我正在尝试相同的 api。

不幸的是,我发现网站 crossorigin.me 已不再维护,并且该域名现在实际上正在出售。

好消息是还有其他方法可以完成这项工作。此外,值得注意的是,在网上搜索了一番后,metaweather api本身很难用ajax获取。如此多的用户为此苦苦挣扎。所以你可能会考虑使用不同的api。请参阅此 github 代码以供参考

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-07-15
    • 1970-01-01
    • 1970-01-01
    • 2023-02-13
    • 1970-01-01
    • 2020-12-23
    • 2021-11-11
    • 1970-01-01
    相关资源
    最近更新 更多