div 内的 Javascript feedreader
实现 JS 脚本来提取/解析 XML 提要并将内容返回到 html 中。不幸的是,它似乎并没有这样做,因为页面上只显示了 div 标签之间的文本(Feed!)。
function loadRSSFeed(param){
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET",'http://feeds.feedburner.com/engadget/Dnjv',false);
xmlhttp.send();
xmlDoc = xmlhttp.responseXML;
var strBuffer= "";
strBuffer = strBuffer +"<table border='1'>";
var x=xmlDoc.getElementsByTagName("item");
for (i=0;i<x.length;i++){
strBuffer = strBuffer +"<tr><td><a href='";
strBuffer = strBuffer +(x[i].getElementsByTagName("link")[0].childNodes[0].nodeValue);
strBuffer = strBuffer +"'>";
strBuffer = strBuffer +(x[i].getElementsByTagName("title")[0].childNodes[0].nodeValue);
strBuffer = strBuffer +"</a></td></tr><tr><td>";
strBuffer = strBuffer +(x[i].getElementsByTagName("description")[0].childNodes[0].nodeValue.substring(0,180));
strBuffer = strBuffer + "<a href='";
strBuffer = strBuffer +(x[i].getElementsByTagName("link")[0].childNodes[0].nodeValue);
strBuffer = strBuffer +"'>... Read More...</a>";
strBuffer = strBuffer +"</td></tr>";
if(i==10){
break;
}
}
strBuffer = strBuffer +"</table>";
document.getElementById(param).innerHTML =strBuffer;
}
它是这样导入的(成功): 然后在体内调用
<body onload ="loadRSSFeed('feeddisplay');">
<h1>All the news that's fit to render</h1>
<div id="feeddisplay">Feed!</div>
</body>
却没有显示出来!页面的其余部分按照预期进行...有什么
想法吗?
Implementing a JS script to pull/parse an XML feed and return the contents into an html . Unfortunately, it doesn't seem to be doing so, as nothing but the text (Feed!) between the div tags appears on the page.
function loadRSSFeed(param){
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET",'http://feeds.feedburner.com/engadget/Dnjv',false);
xmlhttp.send();
xmlDoc = xmlhttp.responseXML;
var strBuffer= "";
strBuffer = strBuffer +"<table border='1'>";
var x=xmlDoc.getElementsByTagName("item");
for (i=0;i<x.length;i++){
strBuffer = strBuffer +"<tr><td><a href='";
strBuffer = strBuffer +(x[i].getElementsByTagName("link")[0].childNodes[0].nodeValue);
strBuffer = strBuffer +"'>";
strBuffer = strBuffer +(x[i].getElementsByTagName("title")[0].childNodes[0].nodeValue);
strBuffer = strBuffer +"</a></td></tr><tr><td>";
strBuffer = strBuffer +(x[i].getElementsByTagName("description")[0].childNodes[0].nodeValue.substring(0,180));
strBuffer = strBuffer + "<a href='";
strBuffer = strBuffer +(x[i].getElementsByTagName("link")[0].childNodes[0].nodeValue);
strBuffer = strBuffer +"'>... Read More...</a>";
strBuffer = strBuffer +"</td></tr>";
if(i==10){
break;
}
}
strBuffer = strBuffer +"</table>";
document.getElementById(param).innerHTML =strBuffer;
}
it is imported like so (successfully):
Then called in the body
<body onload ="loadRSSFeed('feeddisplay');">
<h1>All the news that's fit to render</h1>
<div id="feeddisplay">Feed!</div>
</body>
But it does not show up! The rest of the page does as it's supposed to...
Thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
那不应该是 XMLHttp*Request* 吗?
Shouldn't that be XMLHttp*Request*?
google feed reader api 更强大,并且有更多功能来处理 rss
http://code。 google.com/apis/feed/v1/
另外我认为 onLoad 可能无法找到 div ...?您是否尝试在加载 div feed 后执行脚本...只是我的 2 美分。
The google feed reader api is more robust and has few more features to handle rss
http://code.google.com/apis/feed/v1/
Also I think onLoad may not be able to find the div ... ? did you try executing the script after the div feed was loaded ... just my 2 cents.