1

I would like to reload an image which is constantly updated on the server. So far I have only tried:


setInterval(function(){
        if ($("#stream").data("loaded")) {
            $("#stream").attr("src", "http://keshira.com:8080/?action=snapshot&" + new Date().getTime());
        }
},100); 

<img id="stream" onload="$(this).data('loaded', 'loaded');" src="http://keshira.com:8080/?action=snapshot"/>

Unfortunately this also keeps refreshing the image every 100ms. My problem is that I would like to load new images as fast a possible. So using a larger time interval is no option. Any thoughts are highly appreciated.

2
  • So does this code work? Do you want to update images more often or what? Commented Aug 9, 2014 at 14:30
  • The code updates the image constantly. It should only update the image if the last image has fully loaded. Commented Aug 9, 2014 at 14:38

1 Answer 1

3

Try using load event a bit different:

$("#stream").on('load', function() {
    $("#stream").attr("src", "http://keshira.com:8080/?action=snapshot&" + new Date().getTime());
});

Here is demo. I use setTimeout there only to limit it somehow, but you can remove it.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks simply didn't have enough knowledge of jquery.

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.