A simple example of using Ajax to read RSS seeds

Source: Internet
Author: User
Tags window

Some time ago participated in the first AJAX contest, the results of a few, the first round has not been, depressed in ~ ~ ~

One of the problems is to use AJAX technology to read RSS seeds, the feeling of learning Ajax technology is very enlightening, and now put my implementation code published, for everyone to learn and exchange!

Use XMLHttpRequest to read the ajaxcn.org RSS feed (http://ajaxcn.org/exec/rss) and list the retrieved blog entries with an HTML listing label (UL/OL/LI).

Code implementation:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 strict//en"
"Http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" >
<title>rss reader</title>
<!--Copyright turkeycock-->
<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 () {
Createxmlhttprequest ();
Xmlhttp.onreadystatechange = Handlestatechange;
Xmlhttp.open ("Get", "Http://ajaxcn.org/exec/rss", true);
Xmlhttp.send (NULL);

function Handlestatechange () {
if (xmlhttp.readystate = = 4) {
if (Xmlhttp.status = = 200) {
Clearpreviousresults ();
Parseresults ();

function Clearpreviousresults () {
var listbody = document.getElementById ("Resultstitle");
while (ListBody.childNodes.length > 0) {
Listbody.removechild (Listbody.childnodes[0]);

function Parseresults () {
var results = Xmlhttp.responsexml;
var title = null;
var item = NULL;

var items = results.getelementsbytagname ("item");
for (var i = 0; i < items.length; i++) {
item = Items[i];
title = Item.getelementsbytagname ("title") [0].firstchild.nodevalue;

Addlistrow (title);


function Addlistrow (title) {
var row = document.createelement ("ul");
var cell = Createcellwithtext (title);
Row.appendchild (cell);

document.getElementById ("Resultstitle"). appendchild (row);

function Createcellwithtext (text) {
var cell = document.createelement ("Li");
var textnode = document.createTextNode (text);
Cell.appendchild (Textnode);

return cell;

<form action= "#" >
<input type= "button" value= "Search"/>
<div id= "Resultstitle" ></div>

You can run it in a Web container, I run it in Tomcat 5.5, and I can read the RSS feeds correctly!

Related Article

Cloud Intelligence Leading the Digital Future

Alibaba Cloud ACtivate Online Conference, Nov. 20th & 21st, 2019 (UTC+08)

Register Now >

Starter Package

SSD Cloud server and data transfer for only $2.50 a month

Get Started >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.