在jQuery Mobile中强制刷新图像 [英] Force refresh an image in jquery mobile

查看:60
本文介绍了在jQuery Mobile中强制刷新图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Android,Phonegap,jqm 1.4

Android, Phonegap, jqm 1.4

当用户在我的应用程序中上传新的个人资料照片时,它会在服务器上更改,但是由于img src是相同的路径(相同的路径,新的数据),因此它不会在应用程序中更新(页面刷新,构建新的图像元素等).我必须重新启动应用程序才能进行更改.

When a user uploads a new profile pic in my app, it changes on the server, but since the img src is the same path (same path, new data), it doesn't update in the app (page refresh, building a new image element, etc.) I have to restart the app for the changes to take place.

是否可以仅刷新图像元素,以便它们重新下载图像?

Is there a way to refresh just the image elements so they will redownload the image?

我想它正在缓存图像...我想总体上保持缓存,但是当用户更改图片时只是取消缓存".

I suppose it's cacheing the image... I'd like to keep cacheing in general, but just "un-cache" when a user changes their pic.

注意:此问题在我的Chrome/Ripple仿真器中不会发生,它会在刷新页面时更新.

Note: This problem doesn't happen in my chrome/ripple emulator, it updates on page refresh.

推荐答案

您需要更改图像路径以强制再次下载.为此,请将未使用的URL参数添加到路径的末尾,如下所示:

You need to change the image path to force it to be downloaded again. To do this, add an unused URL parameter to the end of the path, like this:

$("#myimg").attr("src", "/path/to/myimg.jpg?"+ new Date().getTime());
// OR
$("#myimg").attr("src", "/path/to/myimg.jpg?"+ Math.random());

尝试使用jQuery Mobile.

Try it out for jQuery Mobile.

这篇关于在jQuery Mobile中强制刷新图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆