質問

I have a JavaScript function which first of all fetches the value of a label element, which is an ID for a database entry. These ID's then get sent to a ASP page which fetch an images save location from the database.

This save location information for each selected image is then sent to a ASP.NET page which splits each image save location and rotates the images accordingly. This all works perfect, my only issue is that the images will not update until I reopen the HTA file.

Here is my JavaScript which does the rotating:

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();
}

I also have a function which reapplies (well, should do) the background image, which should reload the rotated images. Although reloading the page doesn't work, so I can't see that function working either, but that's a different issue. Here is the function:

function reapplyStyle(id) {
    var background = doc(id+"_label").style.backgroundImage;
    doc(id+"_label").style.backgroundImage = background;
}
役に立ちましたか?

解決

If it is a caching problem, have you tried making the image url unique. Try something like this:

ts = new Date().getTime();
obj.src = "http://localhost/nightclub_photography/images/buttons/"+dir+".png?timestamp=" + ts;
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top