Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

396
Visualizações
Using DataTables, back button doesn't work with multiple AJAX calls in Flask app

I have a simple online directory and file hosting app that allows traversal through the directories.

I am loading the DataTables content using AJAX by clearing all rows in the DataTable and then adding new rows with the updated data. I'm also updating the URL with the current path by using the replaceState function.

Currently I am able to use the back button once and it will load the content of the DataTable from the previous AJAX request, but the page stays static on any following back button presses. The forward button never works.

Code is below:

<script>
    $('body').on('click', '.folder_link', function (){
        folder_path = this.value
        req = $.ajax({
            url:  '{{ url_for(request.endpoint) }}' + folder_path,
            type: 'POST',
            data: {
                "path": folder_path
            },
            success: function(data){
                datatable = $('#datable_documents').DataTable();
                datatable.clear().draw();

                for (var i = 0; i < data['data'].length; i++) {
                    datatable.row.add(data['data'][i]);
                }

                datatable.draw();

                window.history.pushState(
                    {
                        url: '{{ url_for(request.endpoint) }}' + folder_path,
                        data: data
                    },
                    '',
                    '{{ url_for(request.endpoint) }}' + folder_path
                );
                url_next = '{{ url_for(request.endpoint) }}' + folder_path;
                window.history.replaceState(
                    {
                        url: '{{ url_for(request.endpoint) }}',
                        data: data
                    },
                    {},
                    url_next
                );
            },
            error: function(jqXHR, textStatus, errorThrown){
                alert('error');
            }
        });

        $(window).on('popstate', function(event){
            location.reload(true);
        });
    });
</script>
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda