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

Link to comment
Share on other sites

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'>

Link to comment
Share on other sites

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);
  		}
});
}

 

Link to comment
Share on other sites

  • 1 year 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.