IE image caching with jQuery form: Force image rel

2019-08-23 09:49发布

问题:

I have the following code:

$('#imageform').submit(function() {
    $("#imageBox").html('');
    $("#imageBox").html('<img src="img/loader.gif" alt="Uploading...."/>');
    $("#imageform").ajaxSubmit(
    {
        target: '#imageBox',
        resetForm: true
    });
    return false;
});

In IE, the image will be cached and not reload, I wanted to force it to refresh. The problem is that I rename the image in a PHP file, so I wanted to know how to add a paramter (?date) AFTER the image is loaded.

回答1:

Try this:

var counter = 0;
...
$("#imageBox").html('<img src="img/loader.gif?c='+counter+'" alt="Uploading...."/>');
counter++';