Location.Reload(true) does not work

Asked

Viewed 528 times

0

Dear, dropzone use (https://www.dropzonejs.com) on my website and thumbnails (which are on the server) return when deleted using Chrome. In IE and Firefox they work perfectly.

After doing a lot of code redoing, testing solutions, etc., I discovered that by pressing the Shift+F5 keys Chrome reloads the photos from the server instead of the cache and the thumbnails are deleted. Only F5 doesn’t work. The javascript equivalent would be Location.Reload(true) but this does not work in Chrome. Below the code:

// Recupera imagens

    con1.open("GET", arqpath1, true);
    con1.send();
    ...


// Apaga arquivo no servidor

    this.on("removedfile", function(file) {

        $.ajax({
            url: "delfotoprodedit.asp",
            method: "POST",
            data: {
                arqname: file.name
            },

            success: function(data) {
                document.location.reload(true);

            }
        });
    });

I’ve tried a few examples to reload the page without success: http://www.phpied.com/files/location-location/location-location.html

See more examples: Chrome (59.0.3071.115): window.location.Reload(true) reloads from cache, not server as it should...

Would anyone have a solution? Thank you

  • The following is the explanation: https://blogs.msdn.microsoft.com/ieinternals/2010/07/understanding-conditional-requests-and-refresh/

  • I put:<meta http-equiv="cache-control" content="max-age=0" /> <meta http-equiv="cache-control" content="no-cache" /> <meta http-equiv="expires" content="0" /> <meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" /> <meta http-equiv="pragma" content="no-cache" /> Didn’t work, keeps loading the cache.

2 answers

0

I got it, and I want to drop off the tip for a future appointment. Dropzone images returned when deleted so I followed the example below w3schools.com:

// Remove cached result add a unique ID to the URL


xhttp.open("GET", arqpath1 + "?t=" + Math.random(), true);
xhttp.send();

0

I had this same problem, I tell you that the best way would be to change the image Urls, as uses classic Asp (vbscript) could do so:

Function UltimaModificacao(arquivo)
    dim fs, f
    set fs = Server.CreateObject("Scripting.FileSystemObject")
    set f = fs.GetFile("c:\projeto\images\" & arquivo)
    Response.Write(Server.URLEncode(f.DateLastModified))
    set f = nothing
    set fs = nothing
End Function

And on page Asp would add this:

<img src="images/001.jpg?_=<% UltimaModificacao("001.jpg") %>">

<img src="images/abc.jpg?_=<% UltimaModificacao("abc.jpg") %>">

It will be generated as something like this:

Note that the c:\projeto\images\ should be replaced by the physical path of your server/project.


Solving with Javascript

I recommend the first code because with DateLastModified already avoids the user having to press F5 for every thing that changes, however if you really want something like location.reload(true); what you can do is an HTTP pre-request in POST with XmlHttRequest on the front end right after the upload is clear, for example:

function reloadPageAndClearUrl(url)
{
    $.post(url).always(function () {
         document.location.reload(true);
    });
}

...

    $.ajax({
        url: "delfotoprodedit.asp",
        method: "POST",
        data: {
            arqname: file.name
        },
        success: function(data) {
            reloadPageAndClearUrl('<aqui deve ir a url da miniatura da imagem que deseja que seja limpa do cache>');
        }
    });

...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.