0

I'm trying to get an RSS response using $http and I keep getting the following error:

Uncaught SyntaxError: Unexpected token <

The code that tries to get it is:

$http({
            method: 'jsonp',
            url: url,
            params: {
                format: 'jsonp',
                callback: 'JSON_CALLBACK'
            }
        }).success(function (response) {
            myData = response;
        });
3
  • Try post form for method. Commented Jun 20, 2016 at 16:07
  • getting No 'Access-Control-Allow-Origin error when changing to post Commented Jun 20, 2016 at 16:20
  • You need to load your file directly from webserver, not with file:/// protocol, by the way, you can download them with $http.get in case Commented Jun 20, 2016 at 16:22

1 Answer 1

1

You can use googleapi to get the feed:

function getFeed(url, count) {
    var deffered = $q.defer();
    $http
        .jsonp('//ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=50&callback=JSON_CALLBACK&q=' + encodeURIComponent(url))
        .then(function(response) {
            if (!response.data.responseData) {
                return CommonSrv.handleError('Unable to fetch RSS feed from provided URL. Please check the URL.');
            }
            var feeds = response.data.responseData.feed.entries;
            var result = [];
            for (var i = 0; i < count; ++i) {
                var f = feeds[i];
                f.publishedDate = new Date(f.publishedDate).toISOString();
                result.push(f);
            }
            deffered.resolve(result);
        }, CommonSrv.handleError);
    return deffered.promise;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.