Jquery RSS提要到HTML
因此,我有一个RSS提要,可以正确地打印到控制台,没有错误。我可以看到控制台中解析的所有XML都非常漂亮和整洁。当我试图在HTML中显示时,我看到的只是“未定义”。这是我的密码:Jquery RSS提要到HTML,jquery,html,json,parsing,rss,Jquery,Html,Json,Parsing,Rss,因此,我有一个RSS提要,可以正确地打印到控制台,没有错误。我可以看到控制台中解析的所有XML都非常漂亮和整洁。当我试图在HTML中显示时,我看到的只是“未定义”。这是我的密码: <script> $.ajax({ url : document.location.protocol + '//ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=10&callback=?&q=' + enc
<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>
$.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'),
数据类型:“json”,
成功:功能(数据){
if(data.responseData.feed&&data.responseData.feed.entries){
$.each(data.responseData.feed.entries,function(即,e){
console.log(“---------------------------”);
控制台日志(“标题:+e.title”);
console.log(“作者:+e.author”);
控制台日志(“说明:+e.description”);
控制台日志(“链接:+e.link”);
});
}
$('#rss查看器')[0].innerHTML=data.innerHTML;
}
});
非常感谢您的帮助。返回时没有
数据。innerHTML
<代码>数据具有以下属性。响应日期
、.responseDetails
和.responseStatus
除此之外,如前所述,我在几年前写的一篇评论中提到,使用jQuery阅读RSS非常容易。我最近将其发布到get hub,并对其进行了一些更改,使其更易于使用。下面,您将看到一个使用链接和一些非常简单的jQuery的简单示例,用于从返回的提要创建元素并将它们添加到DOM中
最基本的用法:$.jQRSS('http://www.yourRSSurl.com/“,{options},函数(newsFeed,feedEntries){/*dowork!*/})
例子:
$.jQRSS('https://news.google.com/news?cf=all&hl=en&pz=1&ned=us&output=rss“,{count:8},函数(提要,条目){
log('feed:',$(feed));
$。每个(条目、函数(i){
如果(此['content']){
var fieldset=$('',{title:this.contentSnippet}).appendTo('body'),
图例=$('').appendTo(字段集),
$link=$('',{href:this.link,html:this.title,target:''u blank'}).appendTo(图例),
$date=$('',{html:this.publishedDate,style:'float:right;'}).appendTo(fieldset),
$content=$(this.content).appendTo(fieldset);
log('entry'+i+':',$(this));
}
});
});代码>
噢,要跨浏览器,您需要删除我在调试中的几行代码。基本上只需删除所有的console.log
行,因为它们与IE不兼容。另外,$('rss-viewer')[0]。innerHTML=
最好在jQuery中写成“$('rss-viewer').html('')试着直接将e
传递到console.log,看看你是否得到了你认为得到的数据结构。当我做'data=('title:+e.title);'然后是“$”(“#rss查看器”).html(数据);”但它只给了我最后一个头衔。为什么要投否决票?这只是另一种方式,提供了一种易用性
。要么接受,要么放弃。