Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

393
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda