-1
// Page number of datatable
    var table = $('#example1').DataTable();
    var info = table.page.info();   
    pageNo = info.page+1;

    $.ajax({
        url:"<?=ADMIN_PRODUCT_EDIT?>",
        type:"post",
        async:"true",
        data:{pid:id,pageNo:pageNo},
        beforeSend:function(data){
            //alert(data);  
        },
        success:function(data){
            alert(data);
            $("#product_edit_form").html(data);
        },
        error:function(data){
            alert(data);
        },
    });

TypeError: $(...).DataTable is not a function[Learn More] admin_product:2774:14 editProduct http://localhost/healthvit-new/admin_product:2774:14 onclick

Mehravish Temkar
  • 4,275
  • 3
  • 25
  • 44

2 Answers2

1

Check this:

The error was occured when the datatable function is called before the script is loaded correctly or completely.

The below function will call the script, when the function is not found.

   function editProduct(id) {
      if (!$.fn.DataTable) {
         $.getScript('https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js',
                 function (data, textStatus, jqxhr) {
                    if (jqxhr == 200) {
                       if ($.fn.DataTable.isDataTable('.no-ordering')) {
                          var table = $('#dtTable').DataTable();
                       } else {
                          var table = $('#dtTable').DataTable({
                             paging: false,
                             searching: false
                          });
                       }
                       /* var table = $('.no-ordering').DataTable(); */
                       var info = table.page.info();
                       pageNo = info.page + 1;


                       $.ajax({
                          url: "<?= $ADMIN_PRODUCT_EDIT ?>",
                          type: "post",
                          async: "true",
                          data: {pid: id, pageNo: pageNo},
                          beforeSend: function (data) {
                          },
                          success: function (data) {
                             $("#product_edit_form").html(data);
                          },
                          error: function (data) {
                          }
                       });
                    }
                 }
         );
      }
   }
Eugine Joseph
  • 1,552
  • 3
  • 18
  • 40
0

Without seeing the rest of your code, I can only guess that you forgot to include the DataTable library, or only have the CSS. You can find instructions on DataTable's website .

slaughtr
  • 536
  • 5
  • 17