why the setInterval function is not working Jquery Datatables ??

why the setInterval function is not working Jquery Datatables ??

kiran7881kiran7881 Posts: 6Questions: 3Answers: 0

I need to display the Updated data for every 10 seconds in Jquery Datatables .

I will getting this data a flat array JSON (values will be changed ) continously from backend for every 10 seconds

[
    [
        "481.55",
        "10.40",
        "2.21"
    ],
    [
        "561.30",
        "-2.55",
        "-0.45"
    ],
    [
        "368.20",
        "33.45",
        "9.99"
    ]
]
<script>
$(document).ready(function(){
var table = $("#example").dataTable({
   "ajax": {
            "url": "MYURL",
            "dataSrc": ""
        },
        "columns": [
            { "data": 0 },
            { "data": 1 }

        ]
    } );
setInterval( function () {
      table.ajax.reload();
}, 10000 );
});
</script>
<body>


  <table  id="example">
         <thead>
            <tr>
               <th class="hidden-480">Name</th>
               <th class="hidden-480">Price</th>
           
            </tr>
         </thead>
         <tbody>
         </tbody>
      </table>
</body>

Only Initally a call is made to the speciied URL and The Table is shown for the first Time

And never a call is made to the backend again

I am getting this error under browser console

Uncaught TypeError: Cannot read property 'reload' of undefined under browser console at this line table.ajax.reload();

Could anybody please let me know how to fix this ??

This question has an accepted answers - jump to answer

Answers

This discussion has been closed.