js使用ajax读博客rss示例_基础知识

WBOY
Release: 2016-05-16 16:49:46
Original
1005 people have browsed it

复制代码代码如下:

BR> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">


this is test

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 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读rss示例




blogjava原创区
blogjava新手区
blogjava非技术区
综合区


输入一个RSS地址:






Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!