, rss, virkelig simpelt syndikation er vant til at offentliggøre ofte ajourførte oplysninger fra websted som audio, video, billeder, osv. vi kan integrere rss feeds til et websted, ved hjælp af ajax og folkesundhedsprogrammet.denne kode viser, hvordan vise rss feeds i vores sted.,,.,, indeks side bør være følgende −,, < html > < head > < manuskript > funktion showrss (str) (hvis (str.length = = 0) (dokument. getelementbyid ("output"). innerhtml = "" tilbage;} hvis (vindue. xmlhttprequest) (xmlhttp = nye xmlhttprequest();} andre (xmlhttp = nye activexobject ("microsoft. xmlhttp")} xmlhttp. onreadystatechange = function() (hvis (xmlhttp. readystate = = 4 &&xmlhttp. status = = 200) (dokument. getelementbyid ("output "). innerhtml = xmlhttp.responsetext;}} xmlhttp. åben (" gå "," rss.php?q="+str,true); xmlhttp.send(); } </script> </head> <body> <p>Please Select an option to get RSS:</p> <form> <select onchange="showRSS(this.value)"> <option value="">Select an RSS-feed:</option> <option value="cnn">CNN</option> <option value="bbc">BBC News</option> <option value="pc">PC World</option> </select> </form> <br> <div id="output">RSS-feeds</div> </body> </html> , ,rss.php, ,rss.php has contained syntax about how to getadgang til foder og foder til rss tilbage rss websider.,, <?php $q=$_GET["q"]; if($q=="cnn") { $xml=("http://rss.cnn.com/rss/cnn_topstories.rss"); } elseif($q=="bbc") { $xml=("http://newsrss.bbc.co.uk/rss/newsonline_world_edition/americas/rss.xml"); } elseif($q="pcw"){ $xml=("http://www.pcworld.com/index.rss"); } $xmlDoc = new DOMDocument(); $xmlDoc->load($xml); $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 ') - > punkt (0) - > childnodes - > punkt (0) - > nodevalue. echo (< p > < en href = ".channel_link dollars. "> ".channel_title dollars. "< /a > "); echo (< br >"); echo ($channel_desc. "</p>"); $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 dollars. "> ".item_title dollars. "< /a > "); echo (< br >"); echo ($item_desc. "< /p > ")).>,, det giver følgende resultat &minus,,,
php ajax rss foder, f.eks
Previous:php ajax - komplet gennemsøgning
Next Page:php xml - indførelse