用实现ajax读博客rss示例代码
用实现ajax读博客rss示例代码
发布时间:2016-12-29 来源:查字典编辑
摘要:thisistestvarxmlHttp;functioncreateXMLHttpRequest(){if(window.ActiveXO...

this is test var xmlHttp; function createXMLHttpRequest() { if (window.ActiveXObject) { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } else if (window.XMLHttpRequest) { xmlHttp = new XMLHttpRequest(); } } function readRSS(url) { createXMLHttpRequest(); xmlHttp.onreadystatechange = handleStateChange; xmlHttp.open("GET", url, true); xmlHttp.send(null); } function handleStateChange() { if(xmlHttp.readyState == 4) { if(xmlHttp.status == 200) { ResultSet(); } } } function ResultSet() { var results = xmlHttp.responseXML; var title = null; var item = null; var link=null; //得到channel 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=""+headtitle+""; document.getElementById("result").appendChild(cell); //得到items 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=""+title+""; document.getElementById("result").appendChild(cell); } } function readrss1() { var url=document.getElementById("txturl").value; if(url=="") { alert("请输入RSS地址"); } else { readRSS(url); } }

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新AJAX相关学习
热门AJAX相关学习
编程开发子分类