科技行者

行者学院 转型私董会 科技行者专题报道 网红大战科技行者

知识库

知识库 安全导航

至顶网软件频道使用prototype.js写的读取RSS的例子

使用prototype.js写的读取RSS的例子

  • 扫一扫
    分享文章到微信

  • 扫一扫
    关注官方公众号
    至顶头条

使用prototype.js写的读取RSS的例子

作者:baocl 来源:赛迪网技术社区 2007年11月3日

关键字: RSS 读取 Prototype

  • 评论
  • 分享微博
  • 分享邮件

使用prototype.js写的读取RSS的例子,代码如下:
< html>
< head>
< title>ReadRSS< /title>
< script src="common/prototype.js">< /script>
< script>
function send_Request(url)
{
    var request_url =url;//跨域的话,需要写一个代理.
    var request_pars = null;
    var myAjax = new Ajax.Request(
        request_url,
        {
            method:'get',
            parameters:request_pars,
            asynchronous:true,       //true---异步;false---同步.默认为true
            onComplete:processRequest
        }    
    );
}
 
function processRequest(XML_Http_Request){
    var results = XML_Http_Request.responseXML;
    var title = null;
    var item = null;
    var link = null;
    var ccc = results.getElementsByTagName("channel");
    var headtitle = ccc[0].getElementsByTagName("title")[0].firstChild.nodeValue;
    var headlink = ccc[0].getElementsByTagName("link")[0].firstChild.nodeValue;
    var cell = document.createElement("div");
    cell.innerHTML = "< h1>< a href="+headlink+" target=_blank>"+headtitle+"< /a>< /h1>< br>";
    $("result").appendChild(cell);
    var items = results.getElementsByTagName("item");
    for(var i = 0; i <  items.length; i++) {
        item = items[i];
        link=item.getElementsByTagName("link")[0].firstChild.nodeValue;
        title = item.getElementsByTagName("title")[0].firstChild.nodeValue;
        var cell = document.createElement("div");
        cell.innerHTML = "< li>< a href="+link+" target=_blank>"+title+"< /a>< /li>< br>";
        $("result").appendChild(cell);
    }
}
 
var myGlobalHandlers = {
    onCreate:function (){
        Element.show('systemWorking');
    },
    onComplete:function (){
        if(Ajax.activeRequestCount == 0){
            Element.hide('systemWorking');
        }
    }
};
Ajax.Responders.register(myGlobalHandlers);
< /script>
< /head>
< body onLoad="javascript:send_Request('http://esoft.bokee.com/rss2.xml');">
< div id='systemWorking'>Loading...< /div>
< div id="result">< /div>
< /body>
< /html>

查看本文来源
    • 评论
    • 分享微博
    • 分享邮件
    邮件订阅

    如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。

    重磅专题
    往期文章
    最新文章