Forum Moderators: open

Message Too Old, No Replies

I Don't Get Asynchronous Updates

         

mattch80

4:41 pm on Jun 9, 2009 (gmt 0)

10+ Year Member



So this code gets the latest ten dog photos from Flickr using jquery and json. But, how do I get it auto updating when a new photo is available (like twitter search). What are the steps involved?


<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?tags=dog&tagmode=any&format=json&jsoncallback=?",
function(data){
$.each(data.items, function(i,item){
$("<img/>").attr("src", item.media.m).appendTo("#images");
if ( i == 9 ) return false;
});
});
});
</script>
<div id="images"></div>

whoisgregg

9:18 pm on Jun 9, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld, mattch80!

There's no way for the API to notify your site when a new photo is available. How pretty much all AJAX implementations deal with this limitation is by "polling" the data source every so often to see if there is new information.

I'm sure jQuery has some built in functions to make this easier, but I'm not familiar with that library. In plain Javascript, you'd use setTimeout() to set up a function that fires every few seconds/minutes.