在ajax调用之前清除缓存

时间:2014-11-26 11:14:36

标签: ajax caching

大家好,我有以下函数进行ajax调用。我需要用ajax调用图像替换图像。在调用shownewimage函数之前,我需要清除缓存。三江源..

function drawImg(idx)
{
    var imp = document.getElementsByName("img_pan");
    fn = fnArr[parseInt(idx)];
    path = 'designs/' + fn; 

    $("#img_pan").html('<img id="imgView" src="'+path+'"></img>');
    $("#state_info").show();
    var url="newimage.php?fn="+path+"&act='getcolors'";
    httpRequest("GET", url, shownewimage); // i need to clear cache before the shownewimage function executes.
    request.send("");
}

1 个答案:

答案 0 :(得分:1)

事情是你无法从javascript中清除浏览器缓存,所以你需要做的是确保你的服务器对这个newimage.php的响应永远不会被缓存。

尝试PHP:

header('Cache-Control: no-cache, no-store, must-revalidate');   
header('Expires: 0');

或者您可以随时生成随机化的Url / newimage-12345677,您只需要服务器将其映射到实际的PHP脚本。

相关问题