Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Image not reloading - using javascript with random url string added

Posted on 2010-11-09
1
Medium Priority
?
237 Views
Last Modified: 2012-05-10
Hi,

I am changing an image to an ajax spinner, uploading a new image, changin the image back to the original url + a random string to avoid caching.

However, the image does not always update and sometimes needs a reload.

How can I can it to always show the new image?


Thanks.

Julian
0
Comment
Question by:DrZork101
1 Comment
 
LVL 16

Accepted Solution

by:
Justin Mathews earned 2000 total points
ID: 34095449
Your logic should work since every time you are setting the <img> src to a unique value. I guess sometimes browser fails to update the image. If it is in your control I would say change the image name that you upload - something similar to the following:


$(actualImageId).attr({
                                    src     : '../images/imageLoader.gif',
                                    width   :'31',
                                    height  :'31'
                                });
          
          var dummy = Math.floor(Math.random()*9999999);
          ajaxFileUpload(imageId,intDay+dummy);
          
          
          
                    
          $(actualImageId).attr({
                                    src     : '../images/archive/'+intDay+dummy+'img'+imageId+'.jpg',
                                    width   :'140',
                                    height  :'90'
                                });

Open in new window

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question