Uncaught TypeError: Object [object Object] has no method 'api'

Uncaught TypeError: Object [object Object] has no method 'api'

Sangeetha C GSangeetha C G Posts: 5Questions: 2Answers: 0

$(document).ready(function(){
var table1=$('.MessagingTable').DataTable({

});
setInterval( function () {
table1.api().ajax.reload();
}, 10000 );
});
The above reload says has no method 'api' can you please advice?

Answers

  • allanallan Posts: 63,872Questions: 1Answers: 10,526 Site admin

    There is no api() method on the return from $().DataTable(). Just use table1.ajax.reload().

    Allan

  • Sangeetha C GSangeetha C G Posts: 5Questions: 2Answers: 0

    i even tried that , but it throws "Uncaught TypeError: Cannot call method 'reload' of undefined" in console

  • allanallan Posts: 63,872Questions: 1Answers: 10,526 Site admin

    In which case, per the forum rules, could you link to the page so I can debug the issue please.

    Allan

  • Sangeetha C GSangeetha C G Posts: 5Questions: 2Answers: 0
    edited February 2016

    sure thing. but unfortunately the code is in my workspace set up.
    below is the code :
    i had used to create the table using datatable:

    <scriptsrc="http://localhost:8080/js/jquery.dataTables.min.js"type="text/javascript"></script> <table name="Row_Table" id="Row_table" class="bannerTable" style="border: none"> <thead style="border: none"> <th name="1"> </th> <th name="2"> </th> </thead> <tbody> <tr> <td name="IS_ACKNOWLEDGED_ColumnData" class="tableCellList"> </td> <td > <a id="bannerLink"><%=((Bean) (Bean.get(i))).getSubject()%></a> </td> </tr> </tbody> </table> $(document).ready(function(){ var table1=$('.bannerTable').DataTable({ }); setInterval( function () { console.log("table===="+table1); //table1.ajax.reload(); table1.api().ajax.reload(); // table1.api().ajax.reload(); }, 10000 ); });

    i need to load this var table1=$('.bannerTable') for every 1 minute and do the server side call to fetch the new data from server side.

  • Sangeetha C GSangeetha C G Posts: 5Questions: 2Answers: 0
    edited February 2016

    sure thing. but unfortunately the code is in my workspace set up.
    below is the code :
    i had used to create the table using datatable:

    <scriptsrc="http://localhost:8080/js/jquery.dataTables.min.js"type="text/javascript"></script> 
    <table name="Row_Table" id="Row_table"  class="bannerTable"  style="border: none">
                               <thead  style="border: none">
                               <th  name="1">
                               </th>
                               <th  name="2">
                                  </th>
                         </thead>
                         <tbody>
           <tr>
                <td name="IS_ACKNOWLEDGED_ColumnData" class="tableCellList">
               </td>
         <td >
      <a id="bannerLink"><%=((Bean) (Bean.get(i))).getSubject()%></a> 
                    </td>
            </tr>
       </tbody>
                  </table>
    $(document).ready(function(){
                 var table1=$('.bannerTable').DataTable({
                      });
    setInterval( function () {
                       console.log("table===="+table1);
                          //table1.ajax.reload();
                          table1.api().ajax.reload();
                        //  table1.api().ajax.reload();
                        }, 10000 ); 
                  });
    

    Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

  • allanallan Posts: 63,872Questions: 1Answers: 10,526 Site admin

    table1.ajax.reload(); - that option should work.

    If it doesn't, as I say, we would need a link to the page.

    Allan

This discussion has been closed.