开发者

How to refresh an image with Jquery a few seconds after page is loaded

开发者 https://www.devze.com 2023-01-05 12:21 出处:网络
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

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="v开发者_高级运维olumegauge"/>

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


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 ?.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消