Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 67497

How to refresh DIV with AJAX when image is replaced?

$
0
0

I have a online radio station and i wanted to show a album image for every song.Since I have the ability to automatically upload an image of a current playing song (artwork.png) to a web server via ftp, i made a script to display the image on html page..

My Code:

<div id="auto">
  <img id="artwork" src="artwork.png"></img>
</div>
function refresh() {
  setTimeout (function() {
    var timestamp = new Date().getTime();
    $('#auto').html('<img src="artwork.png?timestamp='+ timestamp +'"></img>');

    refresh();
  }, 1000);
}

$('#artwork').attr('src', 'artwork.png?timestamp=' + new Date().getTime());

Everything works great except auto refresh, so i have to manually refresh the page to load a new replaced image. But i want whenever a new image is uploaded to do one refresh on div and that's it. Where is the problem here with refresh();


Viewing all articles
Browse latest Browse all 67497

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>