image src doesnt change after upload

谁说我不能喝 提交于 2019-12-24 05:47:24

问题


i am making an upload with Ajaxupload plugin and i am using this function in OnComplete event of ajaxupload;

function degis(){
var a = "<?php echo $id; ?>";
document.getElementById("imga").src = "../artwork/"+a+"/logo.jpg?dummy=371662";
document.getElementById("imga").style.width = "500px";
document.getElementById("imga").style.height = "175px";
}

but new uploaded image doesnt appear for a reason. i tried that "?dummy=371662" but didnt work.

i am also using this for Onsubmit event of ajaxupload

function updeg(){
var a = "uploading.gif";
document.getElementById("imga").style.width = "50px";
document.getElementById("imga").style.height = "50px";
document.getElementById("imga").src = a;

}
</script>

this is the html of this element

 <img id="imga" alt="" height="175px" src="../artwork/<?php echo $id; ?>/logo.jpg?dummy=371662" width="500px">

Any suggestions on this ?


回答1:


Based on your edits and comments above, I think you need something like this:

function junk() {
    return (new Date()).getTime() + Math.round(Math.random());
}

function degis() {
    var img = document.getElementById("imga");
    if (img) {
        img.src = "../artwork/<?php echo $id; ?>/logo.jpg?nocache=" + junk();
        img.style.width = "500px";
        img.style.height = "175px";
    }
}

Your previous attempt to bypass the cache doesn't work because your "dummy" value is the same each time. By use of a junk() function, as above, you get a different random value each time, ensuring that the image cannot be cached.



来源:https://stackoverflow.com/questions/1626964/image-src-doesnt-change-after-upload

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!