Forum » Izdelava spletišč » ajax php rss reader
ajax php rss reader
cott ::
Sem se cisti zacetnik kar se tice ajax-a in php-ja in se mucim z prilagajanjem ene skripte http://www.w3schools.com/php/php_ajax_r...
Namrec rad bi se znebu "option" in "drop-down" menija. Namest tega bi blo recimo tko, da se doloci rss source v sami skripti in se potem vsak prikaze in avtomatsko refresh-a v svojem locenem div id-ju.
hvala.
----------------------------------------------
------------------------------------------
Namrec rad bi se znebu "option" in "drop-down" menija. Namest tega bi blo recimo tko, da se doloci rss source v sami skripti in se potem vsak prikaze in avtomatsko refresh-a v svojem locenem div id-ju.
hvala.
<form> Select an RSS-feed: <select onchange="showRSS(this.value)"> <option value="Google">Google News</option> <option value="MSNBC">MSNBC News</option> </select> </form> <p><div id="rssOutput"> <b>RSS-feed will be listed here...</b></div></p> </body>
----------------------------------------------
var xmlhttp; function showRSS(str) { xmlhttp=GetXmlHttpObject(); if (xmlhttp==null) { alert ("Your browser does not support XML HTTP Request"); return; } var url="getrss.php"; url=url+"?q="+str; url=url+"&sid="+Math.random(); xmlhttp.onreadystatechange=stateChanged; xmlhttp.open("GET",url,true); xmlhttp.send(null); } function stateChanged() { if (xmlhttp.readyState==4) { document.getElementById("rssOutput").innerHTML=xmlhttp.responseText; } } function GetXmlHttpObject() { if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari return new XMLHttpRequest(); } if (window.ActiveXObject) { // code for IE6, IE5 return new ActiveXObject("Microsoft.XMLHTTP"); } return null; }
------------------------------------------
<?php //get the q parameter from URL $q=$_GET["q"]; //find out which feed was selected if($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>"); } ?>
- spremenil: cott ()
Vredno ogleda ...
Tema | Ogledi | Zadnje sporočilo | |
---|---|---|---|
Tema | Ogledi | Zadnje sporočilo | |
» | AJAX težavaOddelek: Programiranje | 1706 (1175) | tadejp81 |
» | AJAX kratke nalogeOddelek: Izdelava spletišč | 2283 (1750) | Yacked2 |
» | [ajax] osnoveOddelek: Programiranje | 1064 (908) | Volk| |
» | AJAX neznana težavaOddelek: Programiranje | 1198 (992) | luksorzi |
» | java v javascript?Oddelek: Programiranje | 2061 (1764) | boss-tech |