Ajax rss feed not working on localhost -


i'm trying following code w3schools work oh localhost through iis. when run it, can see trying retrieve requested rss feed unfortunately never executes. allows me see options chose never displays them.

many in advance help.

<html>     <head>         <script>             function showrss(str)             {                 if (str.length==0)                   {                   document.getelementbyid("rssoutput").innerhtml="";                   return;                   }                 if (window.xmlhttprequest)                   {// code ie7+, firefox, chrome, opera, safari                   xmlhttp=new xmlhttprequest();                   }                 else                   {// code ie6, ie5                   xmlhttp=new activexobject("microsoft.xmlhttp");                   }                 xmlhttp.onreadystatechange=function()                   {                   if (xmlhttp.readystate==4 && xmlhttp.status==200)                     {                     document.getelementbyid("rssoutput").innerhtml=xmlhttp.responsetext;                     }                   }             xmlhttp.open("get","getrss.php?q="+str,true);             xmlhttp.send();         }         </script>     </head> <body>      <form>         <select onchange="showrss(this.value)">             <option value="">select rss-feed:</option>             <option value="google">google news</option>             <option value="msnbc">msnbc news</option>         </select>     </form>     <br>     <div id="rssoutput">rss-feed listed here...</div>     </body> </html>  

and php file

<?php     header('access-control-allow-origin: *');     //get q parameter url     $q=$_get["q"];      //find out feed 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 "<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 "<channel>"     echo("<p><a href='" . $channel_link       . "'>" . $channel_title . "</a>");     echo("<br>");     echo($channel_desc . "</p>");      //get , output "<item>" elements     $x=$xmldoc->getelementsbytagname('item');     ($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>");       } ?>  

maybe cross platform problem.

if you're using chrome, try opening :

chrome.exe -allow-file-access-from-files 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -