Reload image in Chrome

Asked

Viewed 112 times

2

I created a plugin to cut images through javascript and PHP but I’m having trouble revealing the edited image after the success of Crop in ajax.
I’ve already researched the subject and found a trick that works for most major browsers except Chrome which consists of generating a random string and joining it at the end of the image link.
This is the code I’m using at the moment:

$.post('printmw/ajax_crop', $.param(croper), function(result){
    data = JSON.parse(result);
    if(data.result == 'success'){

        $(active_img).parent().find('img').attr('src', 'images/'+croper['image']+'#'+ new Date().getTime());

    }
}); 

How do I make Chrome free the cached image and reload with the new?

  • 1

    It usually works for me when I put the strings in front (even in Google Chrome). Try, instead of using #, wear a ?. Something that comes back like minha_image.png?78782012124

2 answers

2

Delete the img tag and add it again with the modifications.

  • 4

    Could you give more details and/or examples? To improve the answer and it does not seem so dry.

1

$.post('printmw/ajax_crop', $.param(croper), function(result){
    data = JSON.parse(result);
    if(data.result == 'success'){

       $(active_img).parent().find('img').attr('src', 'images/'+croper['image']+'?t='+ new Date().getTime());

    }
});
  • 4

    Could you explain the reasons for the amendments and further detail your reply?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.