0

I'm trying to create an auto-refreshing RSS ticker feed, where response.php parses the RSS feed, and the HTML file displays the output.

Here's the javascript that's in the HTML file.

<script type="text/javascript" charset="utf-8">

    (function worker() {
        $.get('response.php', function(title) {
            $('.result').html(title);
            setTimeout(worker, 2000);
        });
    })();
</script>

And here's the Response.php.

<? 
require_once('magpierss-0.72/rss_fetch.inc');
$rss = fetch_rss ('http://steamcommunity.com/groups/rsstest/rss');
$item = $rss->items [0]; 
$title = $item[title];
echo $title
?> 

Currently, the javascript parses response.php every two seconds, however I'm clueless as to echoing $title from javascript. Ideally, the current text would be replaced on parsing new information, and would output to a div.

Passerby
  • 9,715
  • 2
  • 33
  • 50
  • just one critique: if you want a function to execute every n milliseconds instead of just one single time after the first n milliseconds, use `setInterval` instead of `setTimeout`. In other words, use `setInterval` to repeat a function, and `setTimeout` to execute a function just once. – bob-the-destroyer Jul 19 '13 at 03:22

1 Answers1

0

If $title is just text change

$('.result').html(title);

to

$('.result').text(title);

You may also consider turning the response into JSON so then later when you decide to add more to it you're good to go. Then use the getJSON function in Jquery

user602525
  • 3,126
  • 4
  • 25
  • 40