Use ajax to automatically load blogjava and rss of the blog site

Source: Internet
Author: User

<! 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;
// 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;
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> & nbsp Author: </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 ("Enter the RSS address ");
}
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;

// Blog
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 ("loaded! ");
I ++;
J ++;
Break;
}
}

</Script>
</Head>
<Body onload = testRead ()>
<H1> ajax-based rss reading example
<Form>

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 ()">
<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>

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.