JQuery - problem updating an image with the same name using attr ('src', newimage)

I am trying to refresh an image on a page, but this does not happen. I have an image page, and I need to update these images as needed. To update the image, I upload the image to the lightbox, and then close it. The image on the page should be updated. Now I tried $ ('# imageid'). Attr ('src', newimage). I want to specifically mention here that the name of both the old and the new images is the same. And I feel that this is a problem. If I hardcode any other image, it appears as soon as the lightbox closes. But when I try to update the image by putting the same image name for the 'src' attribute, nothing will happen.

Can someone help me how can I fix this problem and show an updated image.

Thank.

Edit: Could this be a cache?

+3
source share
3 answers

Probably the best solution, but you can simply outline a parameter to force a new image load.

ie: Set src to newImage+"?"+(new Date()).getTime()

+7
source

If it srcis "foo.png" and you set it srcto "foo.png", I think the destination will probably be optimized by the browser as no-op. Did you try to set srcto "" and then set its name? This should be recorded as a change.

+2
source

, , , buttonclick(). , .

1. , , div.
2. html .
3. iframe, .

id "#image", "#img", id iframe - "#cont"

, .

$('#image').remove();
$('#cont').remove();
$('#img').append(' <iframe src="add.html" id="cont"></iframe> ');

, , , ,

<div id="img">
<img id="image" src="uploads/initial_image.jpg"  >
</div>
Hide result

HTML Iframe.

<img src="effects/intermediate.jpg" id="image">
Hide result

, , , , iframe, , .

0

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


All Articles