ajax.reload() won't work

ajax.reload() won't work

JoeJoeJoeJoeJoeJoe Posts: 50Questions: 13Answers: 1
edited November 2018 in Free community support

I'm trying to do two things.
1.I want ajax to reload the table every 30 seconds
2.I want a button that I can press and it will ajax reload the table.

Problems:
1. I'm getting a "can't reinitialize datatable etc..." error, tried it without putting it inside a function too.

$(function () {
        var table = $('#ex').DataTable({
            ajax: "data.json"
        });

        setInterval(function () {
            table.ajax.reload(null, false); // user paging is not reset on reload
        }, 3000);
})
  1. I'm getting an invalid JSON response (tn/1) error on my code for the button:

    <button id="refresh" class="fas fa-sync-alt fa-lg" style="text-align:right;color:white" type="button"></button>
    
    $("#refresh").click(function () {
            var table = $('#WTM_LOG').DataTable();
            table.ajax.reload();
    })
    

Any help would be appreciated. Thanks.

Answers

  • kthorngrenkthorngren Posts: 20,264Questions: 26Answers: 4,764

    I'm getting a "can't reinitialize datatable etc..

    Your code snippet works here:
    http://live.datatables.net/zunaxupu/1/edit

    Something else must be causing the error. Can you post a link to your page or up my example to replicate the issue?

    I'm getting an invalid JSON response (tn/1)

    Follow the troubleshooting steps in the link provided in the URL. It will show you how to see the response then troubleshooting steps can be taken from there.

    Kevin

This discussion has been closed.