Jump to content

Recommended Posts

I have the upload form and when the image is added, it is displayed on the screen without refreshing the page. It works OK, but when it comes to images with the same type of display shows the previous picture (until refresh the page or click on "view/refresh image" in browser).

 

When I upload an image from another format, then it is display correctly (eg, previous image was .jpg and the new .gif).

 

I have tried various methods to refresh but it does not work.

I tried javascript timeout to view it again but it does not display a new image.

I set timeout for 5 sec to refresh the image and then call this function:

function refreshIMG(link) {
  alert(link);
  document.getElementById("img").src=link;
  }

Also tried to call this function with input button (onclick), but no results. How to refresh image in real time (after Ajax upload)?

 

EDIT: When I click Open image in new tab (in browser) it opens new fresh image...but I cant refresh in real-time...

Link to comment
https://forums.phpfreaks.com/topic/232140-refresh-image-after-upload-ajax/
Share on other sites

When you set the src of the image, add a few random digits on the filename like you would parameters for a normal page:

 

document.getElementById("img").src = link + '?rid=' + Math.random();

 

It'll still point to the same image, but the browser will cache it separately.

  • 2 months later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.