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
  • 45,343
  • 90
  • 210
  • 334

3 Answers3

4

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

AllisonC
  • 2,790
  • 4
  • 26
  • 44
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,059
  • 9
  • 44
  • 65
1

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

<img src="url_goes_here?Math.random()" />
Vimalraj
  • 3,980
  • 1
  • 5
  • 6