I am inserting data with jquery Ajax using form submit, And fetching data to dataTable after form submit, following code giving DataTables warning: table id=mainTable - Requested unknown parameter '1' for row 0, column 1. . . . .
var mainTable = $('.mainTable').DataTable();
$('#Form').submit(function(e) {
  e.preventDefault();
  var form = $(this).serialize();
    $.ajax({
        url: "result.php",
        type: "post",
        data: form 
  }).done(function (data) {
        mainTable .clear().draw();
        mainTable .rows.add(data).draw();
        }).fail(function (jqXHR, textStatus, errorThrown) { 
        });
});
HTML
<div class="content">
    <!-- form start -->
    <form method="post" id="Form">     
            <input type="text" name="id">
            <input type="text" name="name">
            <input type="text" name="class">
        <button type="submit">submit</button>
    </form> 
<table id="mainTable" class="mainTable table table-striped">
  <thead>
    <tr>
      <th>Roll No</th>
      <th>Name</th>
      <th>class</th>
    </tr>
  </thead>
  <tbody>
  </tbody>
</table>
</div>
PHP
$id = $_POST['group_id'];
$rollno = $_POST['roll_no'];
$name = $_POST['name'];
$class = $_POST['class'];
$insert = "insert into students (roll_no,group_id,name,class) values(:roll_no,:id,:name,:class)";
$insert = $db->prepare($insert );
$insert ->bindParam(':roll_no',$rollno);
$insert ->bindParam(':id',$id );
$insert ->bindParam(':name',$name);
$insert ->bindParam(':class',$class);
$insert ->execute();
$fetch = "SELECT roll_no,name,class FROM students where group-id=:id";
$fetch = $db->prepare($fetch );
$fetch ->bindParam(':id',$id);
$fetch ->execute();
$output = array('data' => array());
while($row = $fetch ->fetch(PDO:: FETCH_OBJ)) {
    $id = $row->roll_no;
    $name = $row->name;
    $class = $row->class;
$output['data'][] = array( $id,$name,class);    
} // /while 
echo json_encode($output);
 
    