Changing “src” of an “img” html element doesn't refresh it

匿名 (未验证) 提交于 2019-12-03 01:05:01

问题:

I'm using

$("#my_img").attr("src", "/another_img.png");

inside the "beforeSend" callback of an Ajax request using jQuery, the problem is that the the img isn't being always refreshed to the user, sometimes I saw the new image and sometimes not, is there anyway to force the refresh of the img ? I was thinking that by changing the "src" attribute of the img element was enough to make the engine refresh the image. Thanks !

回答1:

Sounds like it might be a caching issue, try:

$("#my_img").attr("src", "/another_img.png?v=" + new Date().getTime());


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!