Loading RSS feed with AJAX: alternatives to Google Feed API?

对着背影说爱祢 提交于 2019-11-28 06:54:50

Use Yahoo's YQL API:

select * from xml where url = 'https://news.ycombinator.com/rss'

You can request a JSONP feed by adding a callback parameter to the url

https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20xml%20where%20url%20%3D%20'https%3A%2F%2Fnews.ycombinator.com%2Frss'&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=mycallback

Deprecated

My plugin, $.jQRSS uses Google Feed and seems to work just fine, given your exact RSS link:

var rss = 'http://rss.nytimes.com/services/xml/rss/nyt/HomePage.xml';
$.jQRSS(rss, { count: 8 }, function (feed, entries) {
	console.log([feed, entries]);
	$.each(entries, function(i) {
		if (this['content']) {
			var fieldset = $('<fieldset/>', { title: this.contentSnippet }).appendTo('body'),
				legend = $('<legend/>').appendTo(fieldset),
				$link = $('<a />', { href: this.link, html: this.title, target: '_blank' }).appendTo(legend),
				$date = $('<h5 />', { html: this.publishedDate }).appendTo(fieldset),
				$content = $('<div />', { html: this.content }).appendTo(fieldset);
			$content.find('br').remove();
		}
	});
});
fieldset > h5 { float: right; margin-top: 0; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="http://rawgit.com/JDMcKinstry/jQRSS/master/jQRSS.js"></script>
Dave B

One addition to Tony's solution for using YQL - I needed to change the callback value to JSON_CALLBACK to parse the response properly:

'https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20xml%20where%20url%20%3D%20\'' + encodeURIComponent(url) + '\'&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=JSON_CALLBACK'

You can use the script feedburner:

<script src="http://feeds.feedburner.com/feeduri?format=sigpro&nItems=10" type="text/javascript"></script>

All information:

https://support.google.com/feedburner/answer/78991?hl=en

You can use PHP to grab a copy of whatever RSS feed you wish to display, then use client side JavaScript to display the results. The main advantage is you're not subject to daily requests limits that way, which most free RSS API services have, or reliability issues.

http://www.javascriptkit.com/dhtmltutors/ajaxticker/index.shtml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!