用ajax自动加载blogjava和博客园的rss
程序员文章站
2022-07-02 16:58:15
<!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>this is test</title>
<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(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;
var author=null;
var pubdate=null;
var description=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="<h1><a href="+headlink+" target=_blank>"+headtitle+"</a></h1><br>";
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;
author=item.getelementsbytagname("author")[0].firstchild.nodevalue;
pubdate= item.getelementsbytagname("pubdate")[0].firstchild.nodevalue;
// description=item.getelementsbytagname("description")[0].firstchild.nodevalue;
var cell = document.createelement("div");
cell.innerhtml="<a href="+link+" target=_blank>"+title+"</a><font color=red>     作者:</font>"+author+"<br>";
document.getelementbyid("result").appendchild(cell);
//var cell1=document.createelement("div");
//cell1.innerhtml=description;
// document.getelementbyid("result").appendchild(cell1);
}
}
function readrss1()
{
var url=document.getelementbyid("txturl").value;
if(url=="")
{
alert("请输入rss地址");
}
else
{
readrss(url);
}
}
var i=1;
var j=0;
function read()
{
if(j==0)
{
readblogjava();
window.settimeout("testread()",100);
}
}
function testread()
{
window.settimeout("read()",1000);
}
function readblogjava()
{
switch(i)
{
case(1):
i++;
readrss("http://www.blogjava.net/rss.aspx");
break;
case(2):
i++;
readrss(http://beginner.blogjava.net/rss.aspx);
break;
case(3):
i++;
readrss(http://general.blogjava.net/rss.aspx);
break;
case(4):
i++;
readrss(http://life.blogjava.net/rss.aspx);
break;
//博客园的
case(5):
i++;
readrss(http://www.cnblogs.com/rss.aspx);
break;
case(6):
i++;
readrss(http://beginner.cnblogs.com/rss.aspx);
break;
case(7):
i++;
readrss(http://life.cnblogs.com/rss.aspx);
break;
case(8):
i++;
readrss(http://misc.cnblogs.com/rss.aspx);
break;
case(9):
i++;
readrss(http://cio.cnblogs.com/rss.aspx);
break;
case(10):
i++;
readrss(http://news.cnblogs.com/rss.aspx);
break;
case(11):
i++;
readrss(http://bookreview.cnblogs.com/rss.aspx);
break;
case(12):
i++;
readrss(http://job.cnblogs.com/rss.aspx);
break;
case(13):
i++;
readrss(http://gis.cnblogs.com/rss.aspx);
break;
case(14):
i++;
readrss(http://clubs.cnblogs.com/rss.aspx);
break;
case(15):
i++;
readrss(http://software.cnblogs.com/rss.aspx);
break;
default:
alert("加载完毕!");
i++;
j++;
break;
}
}
</script>
</head>
<body onload=testread()>
<h1>ajax读rss示例</h1>
<form >
输入一个rss地址:<input type="text" value="http://www.blogjava.net/wujun/rss.aspx" size=50 id="txturl">
<input type="button" value="查 看" onclick="readrss1()">
<input type="button" onclick="hideobject()" value="test">
</form>
<div id="result"></div>
<embed style="position: absolute;top:1px;left:1px; " align=right
src=http://www.nice.or.jp/~mosmos/free/f105.swf width=200 height=200
type=application/x-shockwave-flash ; quality="high" wmode="transparent"></embed>
</body>
</html>
"http://www.w3.org/tr/xhtml1/dtd/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>this is test</title>
<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(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;
var author=null;
var pubdate=null;
var description=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="<h1><a href="+headlink+" target=_blank>"+headtitle+"</a></h1><br>";
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;
author=item.getelementsbytagname("author")[0].firstchild.nodevalue;
pubdate= item.getelementsbytagname("pubdate")[0].firstchild.nodevalue;
// description=item.getelementsbytagname("description")[0].firstchild.nodevalue;
var cell = document.createelement("div");
cell.innerhtml="<a href="+link+" target=_blank>"+title+"</a><font color=red>     作者:</font>"+author+"<br>";
document.getelementbyid("result").appendchild(cell);
//var cell1=document.createelement("div");
//cell1.innerhtml=description;
// document.getelementbyid("result").appendchild(cell1);
}
}
function readrss1()
{
var url=document.getelementbyid("txturl").value;
if(url=="")
{
alert("请输入rss地址");
}
else
{
readrss(url);
}
}
var i=1;
var j=0;
function read()
{
if(j==0)
{
readblogjava();
window.settimeout("testread()",100);
}
}
function testread()
{
window.settimeout("read()",1000);
}
function readblogjava()
{
switch(i)
{
case(1):
i++;
readrss("http://www.blogjava.net/rss.aspx");
break;
case(2):
i++;
readrss(http://beginner.blogjava.net/rss.aspx);
break;
case(3):
i++;
readrss(http://general.blogjava.net/rss.aspx);
break;
case(4):
i++;
readrss(http://life.blogjava.net/rss.aspx);
break;
//博客园的
case(5):
i++;
readrss(http://www.cnblogs.com/rss.aspx);
break;
case(6):
i++;
readrss(http://beginner.cnblogs.com/rss.aspx);
break;
case(7):
i++;
readrss(http://life.cnblogs.com/rss.aspx);
break;
case(8):
i++;
readrss(http://misc.cnblogs.com/rss.aspx);
break;
case(9):
i++;
readrss(http://cio.cnblogs.com/rss.aspx);
break;
case(10):
i++;
readrss(http://news.cnblogs.com/rss.aspx);
break;
case(11):
i++;
readrss(http://bookreview.cnblogs.com/rss.aspx);
break;
case(12):
i++;
readrss(http://job.cnblogs.com/rss.aspx);
break;
case(13):
i++;
readrss(http://gis.cnblogs.com/rss.aspx);
break;
case(14):
i++;
readrss(http://clubs.cnblogs.com/rss.aspx);
break;
case(15):
i++;
readrss(http://software.cnblogs.com/rss.aspx);
break;
default:
alert("加载完毕!");
i++;
j++;
break;
}
}
</script>
</head>
<body onload=testread()>
<h1>ajax读rss示例</h1>
<form >
输入一个rss地址:<input type="text" value="http://www.blogjava.net/wujun/rss.aspx" size=50 id="txturl">
<input type="button" value="查 看" onclick="readrss1()">
<input type="button" onclick="hideobject()" value="test">
</form>
<div id="result"></div>
<embed style="position: absolute;top:1px;left:1px; " align=right
src=http://www.nice.or.jp/~mosmos/free/f105.swf width=200 height=200
type=application/x-shockwave-flash ; quality="high" wmode="transparent"></embed>
</body>
</html>
上一篇: asp+Ajax简单客户登陆验证
下一篇: 孔雀东南飞