1

i'm trying changing dinamically the src path of a img tag

i have:

<img src="img1.jpg">

Then i upload new photo by iframe and new photo takes the same name (img1.jpg) then by ajax i refresh the src path (which is the same but photo is changed)

The problem is that i use same file name, img doesn't change in browser, guessing cause of browser cache...

Is there any jquery,html or php solution on this?

thanks

itsme
  • 48,972
  • 96
  • 224
  • 345

3 Answers3

4

You could try appending a random query string to the end... img src="img1.jpg?random_string"

AllisonC
  • 2,973
  • 4
  • 29
  • 46
2

You could return the image as a base64 string in the ajax response, and append the data to the img element.

<img src="data:image/jpeg;base64,[STRING GOES HERE]" alt=""/>

This way you will save another request. However, the base64-encoding means a few more bytes are transferred.

Jørgen
  • 8,820
  • 9
  • 47
  • 67
1

Its been cache issue.To resolve this issue use Math.random() as query param

<img src="url_goes_here?Math.random()" />
Vimalraj
  • 6,153
  • 1
  • 7
  • 6