Copy codeThe Code is as follows:
<! 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;
// Obtain the 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 );
// Obtain 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>
";
Document. getElementById ("result"). appendChild (cell );
}
}
Function readrss1 ()
{
Var url = document. getElementById ("txturl"). value;
If (url = "")
{
Alert ("Enter the RSS address ");
}
Else
{
ReadRSS (url );
}
}
</Script>
</Head>
<Body ">
<H1> ajax-based rss reading example <Form>
<A href = "javascript: readRSS ('HTTP: // www.blogjava.net/rss.aspx')"> blogjava original zone </a>
<A href = "javascript: readRSS ('HTTP: // beginner.blogjava.net/rss.aspx')"> blogjava newbie </a>
<A href = "javascript: readRSS ('HTTP: // life.blogjava.net/rss.aspx')"> non-technical area of blogjava </a>
<A href = "javascript: readRSS ('HTTP: // general.blogjava.net/rss.aspx')"> comprehensive area </a>
Enter an RSS address: <input type = "text" value = "http://www.blogjava.net/wujun/rss.aspx" size = 50 id = "txturl">
<Input type = "button" value = "check" onclick = "readrss1 ()">
</Form>
<Div id = "result"> </div>
</Body>
</Html>