Jump to content

[SOLVED] jquery - reload an image?


schilly

Recommended Posts

$(function() {
        //the following selector is for the image you are trying to select/change the src...
        $('.nav a img').hover(
            function() {
                this.src = 'new.jpg'; 
            },
            function() {
                this.src = 'old.jpg';
            }
        );
    });

 

 

and ironically....

 

http://lmgtfy.com/?q=jquery+img

 

first result on google... :-)

I hope this is what you were looking for..

no it's a little different that just a hover. i am creating thumbnails from a video file and if the thumbnail taken from the video is in an undesirable location then i am clicking a button, using ajax to call the script to generate a new image then i just need the existing image to refresh and show the new image.

 

currently have:

function reloadPic(thumb,video,aspect,id){
var string = 'thumb='+thumb+'&video='+video+'&aspect='+aspect;
var imageID = '#' + id;
$.ajax({
	type: "GET",
	url: "newThumb.php",
	data: string,
	success: function(msg){
		var img_src = $(imageID).attr('src');
     		$(imageID).attr('src',img_src); 
  		}
});
}

with the link being:
<input type='button' onClick=\"reloadPic('$thumb1','$movie1','$aspect','$tutorial"."1');\" value='Reload Thumb'>

ok got it working. when reloading from the same url, the browser would always pull from cache so even though the image was different, it would just use the cached version.

 

so i found a hack about adding a query string on an image src to force it to reload instead of using the cached version.

 

function reloadPic(thumb,video,aspect,id){
var string = 'thumb='+thumb+'&video='+video+'&aspect='+aspect;
var imageID = '#' + id;
$.ajax({
	type: "GET",
	url: "newThumb.php",
	data: string,
	success: function(msg){
		var img_src = $(imageID).attr('src');
     		var timestamp = new Date().getTime();
     		$(imageID).attr('src',img_src+'?'+timestamp);
  		}
});
}

 

  • 1 year later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.