tags:

views:

65

answers:

2

I have a webpage with a php generated image that displays a volume gauge. One of the variables in the php image is retrieved from a micro-controller. The variable is not being updated before the page is generated so the volume is displayed incorrectly. I know the image is not being pulled from the cache because if I refresh the page right away the image is displayed correctly.

I am looking for a Jquery script to refresh this one image on the page with an ID of "volumegauge".

<img src="gauge.php?Color=green&MaxScale=79&Value=<Nb_var02>&caption=Volume" id="volumegauge"/>

*This page is only being viewed on an iphone so no need to worry about how it will work in IE.

A: 

Try using setTimeout() in your $(document).ready() function. If you want to refresh that image asynchronously, you can use $.ajax() or its variants to request the "current" version of the image, then plop that into your page.

Ken Redler
It should probably be placed in a $(window).load(function() {/*code*/}); Unlike document.ready, window.load will wait until everything including images are loaded. If you don't care if the images are loaded yet or not, then document.ready would be best.
revil
+2  A: 

Like this:

$(function() {
    setTimeout(function() {
        $('#volumegauge').attr('src', function(i, old) { return old + "&rand=" + new Date; });
    }, 3000);    //3,000 milliseconds
});

If the image's URL has no query string, replace & with ?.

SLaks
This and make the image send the appropriate cache headers
Chris T
Thank you for your effort but that doesn't seam to reload anything. On other scripts that I have tried, that are similar, You can see that it is loading something by the spinning icon on the status bar. With your script it never appears. Thank you again for trying.
eod_punk
@eod_punk: I got the function wrong. Try it again now.
SLaks
@SLaks I tried the updated code and it does try to reload the image but it same image is showing and does not appear to refreshing it. I also added the cache header for no cache. Am I trying to go about this the wrong way? Not sure if you noticed but I added the imd src in the orignal question as well. Thanks again.
eod_punk
What URL does it request?
SLaks
eod_punk