I have a problem about populating datatables.js using json object, Can I use the ajax response value as the data for the datatable?
$.ajax({
url:"php_action/searchloc.php",
type:"POST",
data:{
origin: $('#from').val(),
destination: $('#to').val()
} ,
dataType:"json",
success:function(data){
$('#schedule').dataTable( {
"ajax": data,
columns: []
} );
},
error:function(){
alert("error");
}
});
use the data
option :
$.ajax({
url:"php_action/searchloc.php",
type:"POST",
data:{
origin: $('#from').val(),
destination: $('#to').val()
} ,
dataType:"json",
success:function(result){
$('#schedule').dataTable( {
data: result,
columns: []
} );
},
error:function(){
alert("error");
}
});
DataTables has it's own AJAX functionality that uses jQuery's AJAX method, so you don't need to wrap your dataTable logic inside of a jQuery AJAX call.
$('#schedule').dataTable( {
"ajax": {
url:"php_action/searchloc.php",
type:"POST",
data:{
origin: $('#from').val(),
destination: $('#to').val()
},
dataType:"json",
columns: []
}
} );