For example
The stateChanged () and GetXmlHttpObject functions the same as the php ajax recommendation chapter.
This showRSS () function
Each selection is to perform this function in the input field as follows:
Defines the URL (file) transmitted to the server
Add the URL of a parameter (Q) and the selected options from the drop-down list
Add a random number to prevent the server from using cached files
Call the GetXmlHttpObject function to create an XMLHTTP object. The stateChanged change is triggered when it describes the functional requirements of the object.
The XMLHTTP object and specific website are opened.
Send an HTTP request to the server
PHP page
The JavaScript code required by the web server is a php file named "getrss. php ":
<? Php // get the q parameter from URL $ q =$ _ GET ["q"];
// Find out which feed was selectedif ($ q = "Google") {$ xml = ("http://news.google.com/news? Ned = us & topic = h & output = rss ");} elseif ($ q =" MSNBC ") {$ xml = (" http://rss.msnbc.msn.com/id/3032091/device/rss/rss.xml ");}
$ XmlDoc = new DOMDocument (); $ xmlDoc-> load ($ xml );
// Get elements 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 elements from "<channel>" echo ("<p> <a href = '". $ channel_link. "'> ". $ channel_title. "</a>"); echo ("<br/>"); echo ($ channel_desc. "</p> ");
// Get and output "<item>" elements $ x = $ xmlDoc-> getElementsByTagName ('ITEM'); for ($ I = 0; $ I <= 2; $ 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>") ;}?> Reprinted please indicate from http://www.111cn.net/wy/yw.html