Updating a picture without page reload

前端 未结 6 2022
广开言路
广开言路 2020-12-16 20:41

How would I go about updating an image that gets updated on a server every couple of seconds with out the user having to hit the refresh button, my first guess was ajax but

6条回答
  •  春和景丽
    2020-12-16 21:22

    just use javascript to update the src property of the img.

    HTML:

    
    

    JS:

    document.getElementById("myImage").src = "http://....";
    

    If you want it on a timer, do something like this:

    setInterval(function() { ... }, 4000);
    

    If you have an issue with caching, add a random query string to the end of the url: "?rnd=randomNumberHere"

提交回复
热议问题