网站导航免费论文 原创论文 论文搜索 原创论文 网学软件 学术大家 资料中心 会员中心 问题解答 原创论文 论文素材 设计下载 最新论文 下载排行 论文上传 在线投稿 联系我们
返回网学首页
最新论文 推荐专题 热门论文 素材专题
当前位置: 网学 > 网页素材 > AJAX代码 > 正文
用Ajax读取RSS种子的简单例子
来源:Http://myeducs.cn 联系QQ:点击这里给我发消息 作者: 用户投稿 来源: 网络 发布时间: 11/01/18
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>RSS Reader</title>
<!--copyright Turkeycock-->
<script type="text/javascript">
var xmlHttp;

function createXMLHttpRequest() {
    if (window.ActiveXObject) {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }  
    else if (window.XMLHttpRequest) {
        xmlHttp = new XMLHttpRequest();
    }
}
    
function readRSS() {
    createXMLHttpRequest();
    xmlHttp.onreadystatechange = handleStateChange;
    xmlHttp.open("GET", "http://rss.sina.com.cn/news/china/focus15.xml", true);
    xmlHttp.send(null);
}
    
function handleStateChange() {
    if(xmlHttp.readyState == 4) {
        if(xmlHttp.status == 200) {
            clearPreviousResults();
            parseResults();
        }
    }
}

function clearPreviousResults() {
    var ListBody = document.getElementById("resultsTitle");
    while(ListBody.childNodes.length > 0) {
        ListBody.removeChild(ListBody.childNodes[0]);
    }
}

function parseResults() {
    var results = xmlHttp.responseXML;
    var title = null;
    var item = null;

    var items = results.getElementsByTagName("item");
    for(var i = 0; i < items.length; i++) {
        item = items[i];
        title = item.getElementsByTagName("title")[0].firstChild.nodevalue;

        addListRow(title);
    }

}


function addListRow(title) {
    var row = document.createElement("ul");
    var cell = createCellWithText(title);
    row.appendChild(cell);
    
    document.getElementById("resultsTitle").appendChild(row);
}

function createCellWithText(text) {
    var cell = document.createElement("li");
    var textNode = document.createTextNode(text);
    cell.appendChild(textNode);
    
    return cell;
}
</script>
</head>

<body onload="readRSS();">
  <h2>Blog文章列表</h2>
    <div id="resultsTitle"></div>
</body>
</html>
  • 下一篇资讯: JQuery核心函数小结
  • 网学推荐

    免费论文

    原创论文

    浏览:
    设为首页 | 加入收藏 | 论文首页 | 论文专题 | 设计下载 | 网学软件 | 论文模板 | 论文资源 | 程序设计 | 关于网学 | 站内搜索 | 网学留言 | 友情链接 | 资料中心
    版权所有 电话:013574892963 QQ:3710167 邮箱:Educs@163.com 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
    Copyright 2008-2015 Www.myeducs.Cn All Rights Reserved
    湘ICP备09003080号