Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS RSS feed reader

I'm trying to follow this tutorial for how to create a reader, but it doesn't seem to be working. Specifically, the $http.jsonp(...) call does not seem to work. It hangs for about 20 seconds and then simply returns a GET error.

This is the full Angular code.

var app = angular.module('RSSFeedApp', []);

app.controller("FeedCtrl", ['$scope','FeedService', function ($scope,Feed) {    
    $scope.loadButonText="Load";
    $scope.feedSrc="http://sports.espn.go.com/espn/rss/news";

    $scope.loadFeed=function(e){        
        Feed.parseFeed($scope.feedSrc).then(function(res){
            $scope.loadButonText=angular.element(e.target).text();
            $scope.feeds=res.data.responseData.feed.entries;
        });
    }
}]);

app.factory('FeedService', ['$http', function($http){
    return {
        parseFeed : function(url) {
            return $http.jsonp('//ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=50&callback=JSON_CALLBACK&q='+ encodeURIComponent(url));
        }
    }
}])

Is there a different/better way to do RSS feeds in angular, or am I just missing something obvious?

like image 533
Hoser Avatar asked Aug 10 '26 22:08

Hoser


1 Answers

Figured it out.

My app was not yet hosted out on any external server, it is instead currently just running off my machine and I'm accessing the file location through a browser.

ex:

file:///C:/Users/...

The jQuery call to //ajax.googleapis... then routed to a file location, rather than the web address. Changing //ajax.googleapis... to https://ajax.googleapis... fixed this.

Simple mistake but easy to overlook I suppose.

like image 99
Hoser Avatar answered Aug 13 '26 19:08

Hoser



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!