HTA文件缓存导致重大问题

时间:2013-08-16 16:02:02

标签: javascript ajax internet-explorer caching hta

我有一个JavaScript函数,它首先获取label元素的值,该元素是数据库条目的ID。然后将这些ID发送到ASP页面,该页面从数据库中获取图像保存位置。

然后将每个所选图像的保存位置信息发送到ASP.NET页面,该页面拆分每个图像保存位置并相应地旋转图像。这一切都很完美,我唯一的问题是在重新打开HTA文件之前图像不会更新。

这是我的JavaScript旋转:

function doRotate(dir,obj)
{
    var http = getHTTPObject();
    var http2 = getHTTPObject();
    ids = fetchSelection().toString();

    //Make button animate, visual aid that it is working
    obj.src = "http://localhost/nightclub_photography/images/buttons/"+dir+"_animated.gif";

    http.onreadystatechange = function() 
    {
        //Fetch the save location of selected images
        if (http.readyState == 4 && http.status == 200) {
            //Create URL string to send to rotate script
            var locs = http.responseText;
            locs = locs.split(",");

            //Start of URL 
            var url = "http://localhost/nightclub_photography/net/rotate_script.aspx?dir=" + dir;

            for (var i=0; i < locs.length-1; i++)
            {
                url = url + "&t=" + locs[i];
            }
            //Add random math
            url = url + "&k=" + Math.random();

            http2.onreadystatechange = function() 
            {                   
                if (http2.readyState == 4 && http2.status == 200)
                {

                    //Stop animated button
                    obj.src = "http://localhost/nightclub_photography/images/buttons/"+dir+".png";

                    //Split id's
                    var idsSplit = ids.split(",");
                    for (var k=0; k < idsSplit.length; k++) {
                        reapplyStyle(idsSplit[k]);
                    }
                }
            }
            http2.open("GET", url);
            http2.send();
        }
    }
    http.open("GET", "http://localhost/nightclub_photography/asp/returnDatabaseData.asp?ids="+ids+"&k=" + Math.random());
    http.send();
}

我还有一个功能,可以重新应用(好吧,应该)背景图像,它应该重新加载旋转的图像。虽然重新加载页面不起作用,所以我无法看到该功能正常工作,但这是一个不同的问题。这是功能:

function reapplyStyle(id) {
    var background = doc(id+"_label").style.backgroundImage;
    doc(id+"_label").style.backgroundImage = background;
}

1 个答案:

答案 0 :(得分:2)

如果是缓存问题,您是否尝试过将图片网址设为唯一。尝试这样的事情:

ts = new Date().getTime();
obj.src = "http://localhost/nightclub_photography/images/buttons/"+dir+".png?timestamp=" + ts;