Ajax Read Blog RSS sample

Source: Internet
Author: User
Tags net window
ajax|rss| Blog | example

Code:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 strict//en"
"Http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" >
<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;
Get 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= "document.getElementById ("Result"). AppendChild (cell);
Get 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= "<a href=" +link+ "target=_blank>" +title+ "</a><br>";
document.getElementById ("Result"). AppendChild (cell);
}

}
function Readrss1 ()
{
var Url=document.getelementbyid ("Txturl"). Value;
if (url== "")
{
Alert ("Please enter an RSS address");
}
Else
{
Readrss (URL);
}
}

</script>

<body ">
<form >

<a href= "Javascript:readrss (' http://www.blogjava.net/rss.aspx ')" >blogjava original area </a>
<a href= "Javascript:readrss (' http://beginner.blogjava.net/rss.aspx ')" >blogjava Novice Area </a>
<a href= "Javascript:readrss (' http://life.blogjava.net/rss.aspx ')" >blogjava non-tech zone </a>
<a href= "Javascript:readrss (' http://general.blogjava.net/rss.aspx ')" > Comprehensive area </a>
<br>
Enter an RSS address: <input type= "text" value= "http://www.blogjava.net/wujun/rss.aspx" size=50 id= "Txturl" >
<input type= "button" value= "View" >

</form>
<div id= "Result" ></div>
</body>

Output results:
Http://www.blogjava.net/wujun/archive/2006/06/30/56016.html



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.