Upload and replace image with the same name - upload and cache problem

I am trying to upload an image from the server (same name, but always a new image) in the html tag: #webCamStageImage. While I can upload the image, but the browser does not show me the new image - I think this is a caching problem, because when I turn on "disable WebCore cache" in Safari, it works.

Here is my code:

setInterval(function()
{
  $("#webCamStageImage").attr({'src': "http://picture.jpg"});
}, 5000);

How to change / ddelte / refresh old image?

Chris

+3
source share
2 answers

Try using a URL with a hopeless query string:

setInterval(function()
{
  $("#webCamStageImage").attr({'src': "http://picture.jpg?foo=" + new Date().getTime()});
}, 5000);

URL , , , , - ( ). ( ...).

+8

, :

var randNum = Math.floor(Math.random() 999 + 1);
setInterval(function()
{
  $("#webCamStageImage").attr({'src': "http://picture.jpg?rand=" + randNum});
}, 5000);
+1

Source: https://habr.com/ru/post/1755121/


All Articles