0

When my page loads I have an empty image, after a user inputs the correct query string I parse it and return the id/location of the image using AJAX.

<a class="bigImg rght" style="width:258px;">
<img src="" alt="Slide" width="298" height="224" /></a>

Then I append the new id's into the img src field, but what it is not doing is loading the new image in.

parent_img.attr("src","http://www.mysite.com/files/"
+(data.offset_num)+"/"+(data.offset_id)).fadeIn(1000);

So now my html looks like this:

<a class="bigImg rght" style="width:258px;">
<img src="http://www.mysite.com/files/4823413/008234" alt="Slide" width="298" height="224" /></a>

which is the correct location, but it's not refreshing the image, how can I force it to do so? so the new image is loaded in.

4
  • are you sure that's the right location? That URL is a 404 Commented Jan 28, 2013 at 21:48
  • the URL is correct I just changed it to not use the actual url of my site. Commented Jan 28, 2013 at 21:49
  • Works fine for me: jsfiddle.net/bj4SJ Commented Jan 28, 2013 at 21:53
  • @johnKoerner I forgot to add in the img extension :( Commented Jan 28, 2013 at 22:05

1 Answer 1

1

I worked around this by tacking a random ID onto the end of the image.

var img_src = '/images/path_to_image.jpg?' + new Date().getTime();
$('#img_id').attr('src', img_src);
Sign up to request clarification or add additional context in comments.

2 Comments

This will force the browser to reload the image everytime. Have you tried creating your image element with jquery and then adding it to your document ?
he wants the image to refresh every time, so this will do what he wants. his image tag exists, with no src. by setting the src the way i have posted, it would change it and load the image correctly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.