我有一些javascript代码,可以在网页中动态加载图像:
imageSrc = pid.toString() + '/' + imageName + '/' + num.toString();
//imageSrc = pid.toString() + '/' + imageName; 第一行可以正常工作,但使用第二行会导致图像在加载后不会发生变化。我使用firebug从服务器捕获头文件:
Content-Length 43
Allow GET, HEAD
Expires Sun, 28 Jan 2007 00:00:00 GMT
Server CherryPy/3.1.2
Pragma no-cache
Cache-Control no-cache, must-revalidate
Date Sun, 13 Feb 2011 21:12:31 GMT
Content-Type image/x-png我还在网页的头部添加了行<meta http-equiv="Cache-control" content="no-cache">。
这个问题出现在firefox、IE和chrome中,所以我认为这一定是一个基本问题,而不是浏览器的问题。任何帮助都将不胜感激。
发布于 2011-02-14 05:43:31
缓存失效的典型方法是附加一个搜索字符串(注意PNG后面的问号):
img.src = path +"/"+ name + ".png?" + (new Date().getTime());顺便说一句,您不需要执行.toString(),因为将变量加在一起会使它们成为一个字符串:
"a" + 1 + 1; // "a11"https://stackoverflow.com/questions/4987053
复制相似问题