I write a script code that calls the getdata.php by sending a value ,i am getting the success function response in json format it look like this.
my script code:
<script>
function getId(val) {
alert(val);
$.ajax({
type: "post",
url: "getdata.php",
data: 'id=' + val,
dataType: "JSON",
success: function(response){
console.log(response);
}
/*$('#city').dataTable({
"bProcessing": true,
"sAjaxSource": "JSON.parse(this.response)",
"aoColumns": [
{ mData: 'id' } ,
{ mData: 'vid' },
{ mData: 'date' },
{ mData: 'latitude' },
{ mData: 'longitude' },
{ mData: 'speed' },
{ mData: 'batery' },
{ mData: 'totalkm' },
{ mData: 'intrkm' },
{ mData: 'control' }
]
}); */
});
}
</script>
and my response json data :
{"sEcho":1,"iTotalRecords":2,"iTotalDisplayRecords":2,"aaData":[{"id":"1","vid":"A0001","date":"2019-02-07 15:58:53","latitude":"17.00","longitude":"82.20","speed":"25","batery":"98","totalkm":"8","intrkm":"8","control":"0"},{"id":"2","vid":"A0001","date":"2019-02-07 15:58:53","latitude":"17.10","longitude":"82.30","speed":"26","batery":"97","totalkm":"15","intrkm":"15","control":"0"}]}
console.log(response); gives like
{sEcho: 1, iTotalRecords: 2, iTotalDisplayRecords: 2, aaData: Array(2)}
aaData: Array(2)
0: {id: "1", vid: "A0001", date: "2019-02-07 15:58:53", latitude: "17.00",
longitude: "82.20", …}
1: {id: "2", vid: "A0001", date: "2019-02-07 15:58:53", latitude: "17.10",
longitude: "82.30", …}
length: 2
__proto__: Array(0)
iTotalDisplayRecords: 2
iTotalRecords: 2
sEcho: 1
Now, how to give the response of ajax call to datatables sAjax source and read the colums data and present it in #city. please help me i am strucked here.