Example of reading blog rss using ajax in js

Source: Internet
Author: User

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>

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.