Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

390
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!