有谁能够确定,如何停止 jQuery 缓存它抓取的图像,并反复显示相同的图像?
基本上,图像每 5 秒重新上传一次,因为它充当网络摄像头(如果您检查图像右下角的时间戳,您可以判断它是否已更新)
http://colourednoise.co.uk/scripts/index.htm
谢谢
(抱歉我忘了粘贴代码)
$(function(){
$(document).ready(function() {
var imgs = ['http://www.ramseycommunityradio.co.uk/images/webcam.jpg', 'http://www.ramseycommunityradio.co.uk/images/webcam.jpg']
$("#webcam").attr('src', imgs[1]);
var refreshId = setInterval(function() {
$("#webcam").fadeOut("slow", function() {
var $el = $(this);
$el.attr('src', $.inArray($el.attr('src'), imgs) === 0 ? imgs[1] : imgs[0]);
$el.fadeIn("slow");
});
}, 2000);
});
最佳答案
您可以尝试将更改的查询字符串附加到 URL 上,如果这确实是您的问题,这应该会停止缓存。我在这里看到了这个带有时间戳的完成:how to generate and append a random string using jquery
因此,每次生成图像时,您都会执行以下操作:
var qs = (new Date).getTime();
var url = 'http://www.example.com/images/myimage.jpg?' + qs;
$(el).attr('src',url);
关于javascript - jQuery 不会加载更新的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13879118/