我正在尝试获取新闻网站的提要。以为我会使用谷歌的提要 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/