3
votes

I'm trying to change src dynamically through jquery in a Phonegap Build application, like this

$('#photo_profile').attr('src', fullPath).one("load", function(evt) {
                console.log("load");
            }).each(function() {
              if(this.complete) $(this).load();
            });

But it seems that the img does not refresh while the "load" log is shown each time I change the src.

fullPath is something like file:///storage/emulated/0/MyAppFolder/Media/Profile%20Photos/profile.jpg

And it's a valid path, as if I kill the app, then re-launch it, the displays the correct image.

Am I doing something wrong? Thanks

1

1 Answers

4
votes

Sounds like caching issue. Try to prevent it with some random parameter:

$('#photo_profile').prop('src', fullPath + '?' + Math.random())

Also src is a property, so it makes sense to use prop instead of attr.