3

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

ApheX
  • 685
  • 2
  • 10
  • 26

1 Answers1

4

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.

dfsq
  • 191,768
  • 25
  • 236
  • 258
  • 1
    Thanks dfsq! It works like a charm. I thought that it's a browser only concern, and not an issue in a phonegap application. – ApheX Nov 07 '14 at 13:40