我正在尝试使用$ http获取RSS响应,并且我不断收到以下错误:
Uncaught SyntaxError: Unexpected token <
尝试获取它的代码是:
$http({
method: 'jsonp',
url: url,
params: {
format: 'jsonp',
callback: 'JSON_CALLBACK'
}
}).success(function (response) {
myData = response;
});
答案 0 :(得分:1)
您可以使用googleapi获取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;
}