I have a php script that gets the latest tweet of particular users in JSON format. The JSON is parsed into an AJAX function that displays the latest tweet in an ID on the page. A timer is set for every x seconds to execute the above, retrieving the latest tweet without the user having to refresh the page. This works perfectly.
I am now trying to create a notification feature that displays a notification when there is a new tweet to display. Each tweet has a unique ID called 'id_string' in the JSON retrieved. What I want to do is somehow store the generated id_string's value, and then each time a request is made to retrieve a new tweet, check the new 'id_string' against the stored one, and if it is different then display the notification.
Any ideas on how to go about this would be great?! I've looked into local storage but I'm not very familiar with this, and as far as I'm aware you can't check strings against other strings in local storage.
Here is the necessary code to help with interpreting my question:
PHP to make request to twitter and generate output in JSON format (tweets.php):
require_once('config/FrameFunctions.php');
$output = array();
foreach ($tweeters as $i => $tweeter){
$theTweeter = new Tweeter($tweeter, $tmhOAuth);
$allinfo = $theTweeter->getTweets();
$output[$i] = $allinfo;
}
header("Content-type: application/json");
echo json_encode($output);
The javascript to make the request every x seconds and generate the client output:
$(document).ready(function() {
$('.fancybox').fancybox();
/*
* call ajax function and update latest
*/
var refreshTweets = function() {
console.log("updating..");
$.ajax({url:"tweets.php",success:function(result){
tweets = eval(result);
for(i=0;i<tweets.length;i++){
$("#latesttweet"+(i+1)).html(
tweets[i][0].user.name + ": " + tweets[i][0].text
);
}
}});
}
refreshTweets();
//set the time in milliseconds here for each refresh
setInterval(refreshTweets , 30000); //Interval
});