Problems Arise Due to HTA File Cache

My JavaScript function fetches the value of a label element first, which serves as an ID for a database entry. These IDs are then sent to an ASP page to retrieve the save location of images from the database.

The save location information for each selected image is then passed to an ASP.NET page, where the images are rotated accordingly. Everything works perfectly, except for the fact that the images do not update until I reopen the HTA file.

This is the JavaScript code responsible for image rotation:

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

    //Animate button to indicate it's 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 that should reapply the background image, which would reload the rotated images. However, reloading the page doesn't work, and hence I cannot see that function in action either. Here is the function:

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

Answer №1

When dealing with caching issues, one solution could be to generate a unique URL for the image. Consider implementing the following method:

var timestamp = new Date().getTime();
image.src = "http://localhost/nightclub_photography/images/buttons/"+directory+".png?timestamp=" + timestamp;

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

When using expressjs and typescript, you may encounter an error stating that the type 'typeof <express.Router>' cannot be assigned to the parameter type 'RequestHandlerParams'

Working on my project using expressjs with the latest typescript definition file and typescript 2.3.4 from https://github.com/DefinitelyTyped/DefinitelyTyped. I've set up a router and want to access it from a subpath as per the official 4.x documentat ...

Obtaining the correct information from an array using Ionic's Angular framework

I am currently working with an array of data that contains arrays within each item. I have been able to display the data as needed, except for the IDs. Approach Show arrays within the array Retrieve the IDs of the arrays (excluding the IDs inside the ar ...

Developing web components using angular.js while ensuring compatibility with IE11

I have an angular.js application where I need to initialize a web component. Everything runs smoothly on different browsers, however IE11 seems to have problems with document.importNode The angular.js onInit function is as follows: vm.$onIni ...

@vue/cli for automated unit testing

I'm currently using @vue/cli version 4.5.15 and looking to write tests for my components. However, when I run the command, yarn test:unit I encounter an error that says: ERROR command "test:unit" does not exist. Do I need to perform additional se ...

AJAX hits a wall when trying to load additional data at the bottom

I've been attempting to implement infinite scrolling for SQL data retrieval, but unfortunately, the data is not loading from SQL when using this code. Is there a way to incorporate infinity scroll into this code? To troubleshoot, I tried using echo ...

Encountering the "Local resource can't be loaded" error when attempting to link a MediaSource object as the content for an HTML5 video tag

I'm attempting to make this specific example function properly. Everything runs smoothly when I click the link, but I encounter an error when trying to download the HTML file onto my local machine and repeat the process. An error message pops up sayi ...

Angular page fails to refresh upon addition or deletion of data

There's a recurring issue with my angular application where the page fails to refresh after data manipulation such as addition, editing, or removal. For example, when I add a new item to a list of subjects, it doesn't show up unless I navigate aw ...

Having trouble with Vue image source file paths?

Having an issue with loading an image via file_path on Vue. When using a hardcoded path, it works fine. Refer to the sample code below: JavaScript function getRestaurantsbyId(id) { var restaurants = { "1" : { "name": "xxxx", ...

Is there a way to upload multiple files using expressjs?

I'm looking for a way to efficiently send multiple files, including an entire directory, so that I can access them in another JavaScript file called from an HTML file. const app = require("express")(); const http = require("http"). ...

Mapping the changes in the checkbox of a material tree node

Check out this demo on StackBlitz: Tree View I'm having issues with the tree not displaying as desired. I would like it to look like this: Manager Sublist Manager 1 Manager 2 Manager 3 Could you please review and provide some advic ...

Error 403 with Google Search Console API: Access Denied

Currently, I am attempting to extract data from the GSC Search Analytics API using Python. Despite diligently following this resource, I have encountered an error that persists despite multiple attempts to remedy it: raise HttpError(resp, content, uri=se ...

Having trouble toggling journal entries in an HTML journal? The Jquery function might not be working properly

I have been tasked with creating a civil war journal for my 8th grade Social Studies class and I decided to present it as an HTML file featuring the title and date of each journal entry. The goal is to allow users to click on each entry to open it while au ...

Accessing Child Properties in Parent Component using Typescript

New to the world of Typescript! Imagine having a component called TitleSubtitle that consists of both a Title and a Subtitle component. The Title component comes with props: interface TitleProps { text: string; } The Subtitle component also has props ...

MySQL field being updated upon page unload

I'm currently developing a Content Management System (CMS) that allows users to access and organize records within a MySQL database. One of the features I have implemented is a user login system for the CMS. As part of this project, I am working on in ...

Utilizing jQuery Ajax to retrieve a multitude of data

Utilizing jQuery AJAX to retrieve a string from PHP containing JavaScript, PHP, and HTML has been successful for me using the code below: header("Content-Type: text/html"); echo $content; $.ajax({ type: 'POST', url: url, data: data, ...

Monitor the execution of JavaScript callbacks without the need for layering functions

Currently, I am developing a function that involves multiple database calls and needs to store their results in an array before triggering a callback. Let me share some pseudocode for better understanding: function getData (array, callback) { var resu ...

What is the best approach to animating a specified quantity of divs with CSS and javascript?

How neat is this code snippet: <div class="container"> <div class="box fade-in one"> look at me fade in </div> <div class="box fade-in two"> Oh hi! i can fade too! </div> <div class="box fade-in three"& ...

What is the best way to dynamically insert an object into a field name in react-final-form?

When using the react-final-form component, you can expect the following result: <Field name="answers[0].name" component="input" type="radio" value="0" /> { answers: [ { name: 'value' } ] ...

Are there any publicly accessible Content Delivery Networks that offer hosting for JSON2?

Everyone knows that popular tech giants like Google and Microsoft provide hosting for various javascript libraries on their CDNs (content distribution networks). However, one library missing from their collection is JSON2.js. Although I could upload JSON2 ...

Javascript encounters an unforeseen < token

I encountered an unexpected token < error in my JavaScript file. Despite checking the code using JSHint, I couldn't find any issues that could resolve the problem. I attempted to place the JavaScript code in a separate file and also tried embeddin ...