Reload image in Chrome

2

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

$.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 free the cached image and reload with the new one?

    
asked by anonymous 05.01.2015 / 13:05

2 answers

2

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

    
05.01.2015 / 20:54
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());

    }
});
    
05.01.2015 / 21:49