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