Using AJAX to read blog RSS sample code _ajax related

Source: Internet
Author: User
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 strict//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" > <ptm L xmlns= "http://www.w3.org/1999/xhtml" > <pead> <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 VarCcc=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= "<p>" +headtitle+ "</p>"; 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= "" +title+ ""; document.getElementById ("Result"). AppendChild (cell); The function Readrss1 () {var Url=document.getelementbyid ("Txturl"). Value; if (url== "") {alert ("Please enter an RSS address"); } else { Readrss (URL); }} </script> </pead> <body "> <p>ajax Read RSS example </p> <form > B Logjava Original area   Blogjava Novice area   Blogjava non-technical area   Integrated area Enter an RSS address: <input ty Pe= "text" value= "http://www.blogjava.net/wujun/rss.aspx" size=50 id= "Txturl" > <input type= "button" value= "View" Onclick= "Readrss1 ()" > </form> <div id= "result" ></div> </body> </ptml>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]
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.