1

I have this code:

var myRSS =[];

function rssReader() {

    $.getJSON('bbc.php', function(data){
        console.log(data);
        $.each(data[0].channel.item, function(index, item){
            // check if item title is stored in the array   
            if (jQuery.inArray(item.title, myRSS)) { 
                //do nothing
                console.log('hello');
            } else {
                // save item title in the array
                myRSS.push(item.title);
                console.log(myRSS);

                // publish item  
                $('.container').append("<a href='" + item.link + "' class='title' data-date='" + item.pubDate + "'>" + item.title + "</a>");
            }
        });

    });

}

setInterval(rssReader(), 5000);

Now, the first time i run this, it always logs 'hello', so it always falls in the first IF statement. Has anyone any idea why?

Here is the relevant PHP as well:

<?php

$data = file_get_contents('http://newsrss.bbc.co.uk/rss/sportonline_uk_edition/football/rss.xml');

$xml = simplexml_load_string($data);

$data1 = file_get_contents('http://www.skysports.com/rss/0,20514,11661,00.xml');

$xml1 = simplexml_load_string($data1);

$master[0] = $xml;
$master[1] = $xml1;

echo json_encode($master);

?>

1 Answer 1

3

Try checking explicitly for -1

if (jQuery.inArray(item.title, myRSS) != -1) { 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.