Using AJAX / jQuery to refresh an image

前端 未结 4 1260
生来不讨喜
生来不讨喜 2020-12-06 15:04

This is probably a simple question but I am stumped and just don\'t know where to start.

I have a PHP script (image_feed.php) that returns a URL to an image. Every t

4条回答
  •  有刺的猬
    2020-12-06 15:31

    You can. When you want to reload something, you can just append a search query, so that it refreshes the source.

    For Eg., when there is a frequently changing image (say captcha) and you wanna load it again, without refreshing the browser, you can do this way:

    Initial Code:

    captcha
    

    Refreshed Code:

    captcha
    

    The script used here would be just:

    var d = new Date();
    $('img').attr('src', $('img').attr('src') + '?_=' + d.getMilliseconds());
    

    Hope this helps! :)

提交回复
热议问题