【发布时间】:2015-04-17 07:26:17
【问题描述】:
我正在尝试获取新闻网站的提要。以为我会使用谷歌的提要 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 无法加载 http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=10&q=http%3A%2F%2Ffeeds.feedburner.com%2Fmathrubhumi。 请求中不存在“Access-Control-Allow-Origin”标头 资源。因此,不允许访问 Origin 'http://localhost'。
我该如何解决这个问题?
【问题讨论】:
-
我在这里测试了您的代码,使用 Chrome 并按预期工作。您是否尝试过使用“crossDomain: true”属性?
-
我在这里托管了您的代码:learnwithdaniel.com/test.html。看看能不能正常打开。如果您没有收到错误,则问题出在您的服务器上
-
太棒了。因此,它与您的浏览器请求此 html 时服务器发送的标头有关。检查“cors headers”
-
这里和godaddy api一样
-
这个问题不是重复的吗? stackoverflow.com/questions/20035101/… 更重要的是,this other question有更清晰/更彻底的答案。
标签: javascript jquery json ajax cors