Finally succeeded to do it:
$("#classid").change(function(){
var sessionid = $("#sessionid").val();
var classid = $(this).val();
$.ajax({
url : "<?php echo site_url('Ajax/getStudents'); ?>",
method : "POST",
data : {sessionid: sessionid, classid: classid},
async : true,
dataType : 'json',
success: function(data)
{
$('#example').DataTable({
destroy: true,
data : data,
columns: [
{ data: 'studentname', title: "StudentName" },
{ data: 'fathername', title: "Father Name" },
{ data: 'rollno', title: "RollNo" },
{ data: 'mobile1', title: "Mobile" }
],
dom: 'Bfrtip',
iDisplayLength: 15,
buttons: [
'copyHtml5',
'excelHtml5',
'csvHtml5',
'pdfHtml5',
'pageLength'
],
search: true
});
}
});
return false;
});