Angular $http and Google Feed API
Angular $http and Google Feed API
我是一个初学者,"任务"是在Angular/Ionic项目中使用RSS提要。我既可以自己解析RSS提要,也可以使用外部工具,如Google feed API。
我创建了一个服务来获取数据,然后由Angular控制器使用。
这是服务:
.factory('rssReader', ['$http', function($http) {
return $http.get('URL_HERE')
.success(function(data) {
alert("SUCCESS!!!" + data);//return data;
})
.error(function(data) {
alert("FAILED!!!!" + data);//return data;
});
}]);
使用CodeCademy URL给出"SUCCESS"警报并返回JSON数据:
http://s3.amazonaws.com/codecademy-content/courses/ltp4/events-api/events.json
但是,这个Google Feed API URL返回null。示例URL:
http://ajax.googleapis.com/ajax/services/feed/load?v=2.0& http://rss.cnn.com/rss/cnn_topstories.rss&q =; num = 5
我在网上看到过不同的例子,但我试图理解为什么这不起作用。
- 怎么了?
- 我可以用来调试的技巧/工具是什么?
我是Angular和JavaScript的新手,所以感谢任何帮助。谢谢!
你的实现是正确的,(即使它看起来像你正在调用。success函数,无论是在你的服务和控制器)-但我认为真正的问题实际上在于你试图调用的资源。
当我调用s3。amazon的feed,我得到您所描述的数据,但是当调用GoogleAPI时,XMLHttpRequest由于CORS而被阻塞。你可以在CORS(跨域资源共享)头文件中了解更多。
避免这种情况的一种方法是,从服务器端处理对Google API的请求,而不是直接在浏览器中处理。希望这对你有帮助
相关文章:
- JavaScript回调函数和Google Feed API
- Google Feed API-返回媒体:缩略图
- Consume Google Feed API with Phantomjs
- 如何在使用Google Feed API时获取帖子ID
- YouTube feed API (JSON-P) 返回无效的 JS
- Google Feed API跳过文章
- Google Feed API'发布日期'错误的一天
- 使用AJAX加载RSS提要:Google feed API的替代方案
- Twitter Feed API停止工作
- Google AJAX Feed API:无法读取属性'LINK_TARGET_BLANK'的定义
- Google Feed API -从RSS提要加载缓存结果
- Google Feed API日期到HTML5日期时间
- 如何在页面加载中访问由Google feed API返回的值
- Google Feed API是否支持从RSS提要返回图像?
- Google Feed API: more than one feed
- 使用javascript (feed API)从rss提要获取图像
- 使用Google feed API阅读Twitter RSS
- 博客JSON Feed API超过500个帖子
- Google Feed API -从Feed加载图片失败
- 从Google Feed API同时绘制多个提要