javascript - 请求的资源错误中不存在 'Access-Control-Allow-Ori

我正在尝试获取新闻网站的提要。以为我会使用谷歌的提要 API 将 feedburner 提要转换为 json。以下网址将从提要中返回 10 篇 json 格式的帖子。 http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=10&q=http://feeds.feedburner.com/mathrubhumi

我使用下面的代码来获取上面url的内容

$.ajax({
  type: "GET",
  dataType: "jsonp",
  url: "http://ajax.googleapis.com/ajax/services/feed/load",
  data: {
    "v": "1.0",
    "num": "10",
    "q": "http://feeds.feedburner.com/mathrubhumi"
  },
  success: function(result) {
    //.....
  }
});

但它不起作用,我收到以下错误

XMLHttpRequest cannot load http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=10&q=http%3A%2F%2Ffeeds.feedburner.com%2Fmathrubhumi. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access.

我该如何解决这个问题?

最佳答案

如果您使用 Google Chrome 浏览器,您可以使用扩展程序破解。

您可以找到 Chrome extension这将在您的应用程序中动态修改 CORS header 。显然,这只是 Chrome,但我喜欢它可以在任何地方进行零更改。

您可以使用它在本地机器上调试您的应用程序(如果一切都在生产环境中正常运行)。

通知: 如果 URL 损坏,扩展名是 Access-Control-Allow-Origin: * 。我建议您在不处理内容时禁用此扩展程序,因为例如 youtube 不适用于此扩展程序。

关于javascript - 请求的资源错误中不存在 'Access-Control-Allow-Origin' header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28547288/

相关文章:

javascript - 未捕获的类型错误 : Cannot use 'in' operator t

python - 如何在 Python 中美化 JSON?

json - AngularJS:工厂 $http.get JSON 文件

python - 如何在单元测试中使用 JSON 发送请求

json - json.js 和 json2.js 的区别

json - 如何使用 jq 从 JSON 中获取键名

json - 在 VS Code 中,禁用错误 "Comments are not permitte

javascript - 将 JSON 发送到服务器并返回 JSON,无需 JQuery

c# - 解析值时遇到意外字符

sql - 查询 JSON 类型内的数组元素