Related knowledge points about Ajax RSS Reader

Source: Internet
Author: User
The RSS reader is used to read the RSS feed, which is the basis of this tutorial.

Example explanation-HTML page

When the user selects a rss-feed in the drop-down list above, a function named "Showrss ()" is executed. This function is triggered by the "onchange" event:

The Showrss () function performs the following steps:

Check if any rss-feed are selected

Create a XMLHttpRequest Object

Create a function that executes when the server responds ready

Send a request to a file on the server

Note the parameter (q) added to the end of the URL (contains the contents of the drop-down list)

PHP file

File Rss_demo.xml.

The above server page that is called by JavaScript is a php file named "getrss.php":

<?php//rss file $xml= "Rss_demo.xml"; $xmlDoc = new DOMDocument (); $xmlDoc->load ($xml);//Read element from ' <channel> ' channel= $xmlDoc->getelementsbytagname (' channel ')->item (0); $channel _title = $channel getElementsByTagName (' title ')->item (0)->childnodes->item (0)->nodevalue; $channel _link = $channel getElementsByTagName (' link ')->item (0)->childnodes->item (0)->nodevalue; $channel _desc = $channel getElementsByTagName (' description ')->item (0)->childnodes->item (0)->nodevalue;//output "<channel>" The element in Echo ("<p><a href="). $channel _link. ">". $channel _title. "</a>"), Echo ("<br>"), Echo ($channel _desc. "</p>");//output "<item>" element $x= $xmlDoc->getelementsbytagname (' item '); for ($i =0; $i <=1; $i + +) {$item _    title= $x->item ($i)->getelementsbytagname (' title ')->item (0)->childnodes->item (0)->nodevalue; $item _link= $x->item ($i)->getelementsbytagname (' link ')->item (0)->chIldnodes->item (0)->nodevalue; $item _desc= $x->item ($i)->getelementsbytagname (' description ')->item (0)->childnodes->item (0)    NodeValue; Echo ("<p><a href=". $item _link. ">". $item _title.    "</a>");    Echo ("<br>"); Echo ($item _desc. "</p>");}? >

When a request for an RSS feed is sent from JavaScript to a PHP file, it occurs:

Check which RSS feed is selected

To create a new XML DOM object

Loading an RSS document in an XML variable

Extracting and outputting elements from the channel element

Extracting and outputting elements from the item element

This article on the Ajax RSS reader of the relevant knowledge points are explained, more learning materials clear focus on the PHP Chinese network can be viewed.

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.