Simple ajax.reload() example not working

Simple ajax.reload() example not working

randomname456randomname456 Posts: 2Questions: 1Answers: 0

Description of problem:
I'd like to make use of the documented ajax.reload function, but I can't get this function to work. It would be nice if anyone can point out my mistake, or show me a working example for using the ajax.reload function... I've created a (simple) test case that demonstrates the problem. You should open the console to see the exception appear.

Link to test case:
~~ --> Not sure this example is transferrable to others...


<!DOCTYPE html>
        <script src="" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
        <script src="" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
        <script type="text/javascript" src=""></script>
        <script type="text/javascript" src=""></script>
        <meta charset=utf-8 />
        <title>DataTables - JS Bin</title>
        <div class="container">
            <table id="example" class="display" width="100%">
                        <th>Start date</th>

                        <th>Start date</th>
// Server-side processing with object sourced data
$(document).ready(function() {
    var table = $('#example').dataTable( {
        "processing": true,
        "serverSide": true,
        "ajax": "/ssp/objects.php",
        "columns": [
            { "data": "first_name" },
            { "data": "last_name" },
            { "data": "position" },
            { "data": "office" },
            { "data": "start_date" },
            { "data": "salary" }
    } );

    // why doesn't reload work?
    // it's done according to

} );

Error messages shown:
"TypeError: Cannot read properties of undefined (reading 'reload') at HTMLDocument.<anonymous>


  • colincolin Posts: 14,618Questions: 1Answers: 2,497

    It appears to be working in this example from this thread. Clicking on "Change" and you'll see the table change, then the "Reload" gets the original data back.

    Could you look at that, please, and see if it helps. If it's still not working for you, please can you update my example, or link to your page, so that we can see the problem.



  • kthorngrenkthorngren Posts: 17,759Questions: 25Answers: 4,216
    edited February 2022

    The link to your test case doesn't seem to work. There are two problems. The first is the ajax call is asynchronous. The ajax process isn't complete when table.ajax.reload(); is executed which means Datatables initialization isn't complete and the table variable is still undefined.

    The second is to use the Datatables API you need to use $('#example').DataTable( ... );. Notice the D. See the [Accessing the API docs}( for more details.

    Here is an example using a button to reload the table:

    To execute code once Datatables initialization is complete use initComplete or init.


  • randomname456randomname456 Posts: 2Questions: 1Answers: 0

    It seems I cannot edit my own post above, so I'll add this separately:

    I found the problem. The ajax functions can be called, via the api(). For the above example it should be like this:


    I'm sorry for wasting anyone's time.

  • colincolin Posts: 14,618Questions: 1Answers: 2,497

    Easily done, thanks for posting back,


Sign In or Register to comment.