location.reload (true) does not work

0

Expensive, use Dropzone ( link ) on my site and the thumbnails (which are on the server) return when deleted using Chrome. In IE and Firefox work perfectly.

After much redo code, testing solutions, etc., I discovered that by pressing the Shift + F5 keys Chrome recharges the server photos instead of the cache and the thumbnails are deleted. Only F5 does not 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 have already tested some examples to reload the page to no avail: link

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? Thanks

    
asked by anonymous 20.08.2018 / 15:46

2 answers

0

I have succeeded and I want to leave the tip for future reference. The Dropzone images returned when they were 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();
    
21.08.2018 / 16:57
0

I had this same problem, I tell you that the best way would be to change the URLs of the images, as using classic asp (vbscript) could do this:

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 in the asp page I 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 c:\projeto\images\ must be changed by the physical path of your server / project.

Resolving with JavaScript

I recommend the first code because with DateLastModified already prevents 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-requisition on POST with XmlHttRequest on the side of the front end just 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>');
        }
    });

...
    
21.08.2018 / 18:39