如何防止动态图片缓存

时间:2017-10-01 10:43:23

标签: javascript php jquery mysql

我有一个网站,人们可以上传自己的个人资料图片。我将个人资料图片放到我的服务器根文件夹中,名称为“hisusername.jpg / png”,然后在DB中写入图片的位置,如:“../ profile / username.jpg”。现在我的问题是...... 上传后,我打开一个缩放器框,用户可以调整其个人资料图片,使其适合配置文件图片框。我用php get-url动态调用新图像来触发没有缓存:“../ images / username.jpg?number = randomgeneratednumber”。但现在它没有按预期工作,我不知道为什么做什么。我还在寻找一个不错的答案。

    var frm3 = $('#uploadimg');
frm3.submit(function (evenn) {
    $('#uploadprc').show();
    swing();
    $.ajax({
        type: frm3.attr('method'),
        url: frm3.attr('action'),
        data: new FormData(this), // Data sent to server, a set of key/value pairs (i.e. form fields and values)
        contentType: false,       // The content type used when sending data to the server.
        cache: false,             // To unable request pages to be cached
        processData:false,
        success: function (response) {
            var rand= Math.floor((Math.random() * 1000000000) + 1000000);
            var rand2= Math.floor((Math.random() * 1000000000) + 1000000);
            $('#centersizer').removeData();
            $('#usercode').load('php/userpanel.php');
            $('#resp').text(response);
            showntf();
            setTimeout(function() {
            if(response == "The file has been uploaded."){
            $('#profpic').css('background-image','url(<? echo $result['profimg']; ?>?mark='+rand+')');
            $('#centersizer').load('../widgets/resizertool.php');
            $('#resizewrapper').show();
            }
            }, 1000);
            setTimeout(function(){
                $('#imageholder').css('background-image','url(<? echo $result['profimg']; ?>?mark='+rand2+')');
            },1200);
        }
    });

    evenn.preventDefault();
});

0 个答案:

没有答案
相关问题