div 内的 Javascript feedreader

发布于 2024-12-11 06:21:35 字数 1658 浏览 0 评论 0原文

实现 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

守不住的情 2024-12-18 06:21:35

那不应该是 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文