[英]Jquery RSS feed to HTML
So I have an RSS feed that is printing correctly to the console with no errors. 因此,我有一个RSS提要,可以正确打印到控制台,没有任何错误。 I can see all the XML parsed in the console all nice and neat. 我可以看到在控制台中解析的所有XML都很好。 When I try to display in my HTML all I see is "undefined". 当我尝试在HTML中显示时,我看到的是“未定义”。 Here is my code: 这是我的代码:
<script>
$.ajax({
url : document.location.protocol + '//ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=10&callback=?&q=' + encodeURIComponent('https://news.google.com/news?cf=all&hl=en&pz=1&ned=us&output=rss'),
dataType : 'json',
success : function (data) {
if (data.responseData.feed && data.responseData.feed.entries) {
$.each(data.responseData.feed.entries, function (i, e) {
console.log("------------------------");
console.log("title : " + e.title);
console.log("author : " + e.author);
console.log("description: " + e.description);
console.log("link: " + e.link);
});
}
$('#rss-viewer')[0].innerHTML = data.innerHTML;
}
});</script>
<div id="rss-viewer"></div>
Any help greatly appreciated. 任何帮助,不胜感激。
There's no data.innerHTML
on the return. 返回上没有data.innerHTML
。 data
has the properties . data
具有属性。 responseDate
, .responseDetails
, and .responseStatus
. responseDate
, .responseDetails
和.responseStatus
。
That aside, as aforementioned in a comment, I wrote this plugin years ago that makes reading RSS with jQuery extremely easy. 除此之外,正如评论中提到的,我几年前写了这个插件 ,使使用jQuery读取RSS非常容易。 I've recently posted it to get hub and made a few changes to it so it's even easier to use. 我最近发布了它以获取集线器,并对它进行了一些更改,使其更易于使用。 Below, you'll see a simple example using your link and some very simple jQuery for creating elements from the returned feed and adding them to the DOM. 在下面,您将看到一个使用链接的简单示例,以及一些非常简单的jQuery,用于根据返回的供稿创建元素并将其添加到DOM。
Most basic use: $.jQRSS('http://www.yourRSSurl.com/', { options }, function (newsFeed, feedEntries) { /* do work! */ })
最基本的用法: $.jQRSS('http://www.yourRSSurl.com/', { options }, function (newsFeed, feedEntries) { /* do work! */ })
$.jQRSS('https://news.google.com/news?cf=all&hl=en&pz=1&ned=us&output=rss', { count: 8 }, function (feed, entries) { console.log('feed:', $(feed)); $.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, style: 'float:right;' }).appendTo(fieldset), $content = $(this.content).appendTo(fieldset); console.log('entry '+i+':', $(this)); } }); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="http://rawgit.com/JDMcKinstry/jQRSS/master/jQRSS.js"></script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.