No data available in table
No data available in table
benk21
Posts: 1Questions: 1Answers: 0
Hi,
I am getting No data available in table. I tried to fix this myself but I couldn't figure it out. This is a ajax POST data.
This is my .php
return response()->json(['data'=>$query]);
And this is my json
{
"data": [{
"phone_number": "22982001",
"ccompany": "Testing Company",
"ctitle": "",
"cfname": "",
"clname": "",
"caddr1": "994 street",
"caddr2": "",
"caddr3": "",
"cemail": "email@testing.com
}, {
"phone_number": "22982002",
"ccompany": "Testing Company 2",
"ctitle": "",
"cfname": "",
"clname": "",
"caddr1": "995 street",
"caddr2": "",
"caddr3": "",
"cemail": "email2@testing.com
}]
}
**My JS: **
var form = document.forms.namedItem("goodleads");
var formdata = new FormData(form);
var url = "/goodleads";
$.ajax({
async: true,
type: "POST",
contentType: false,
url: url,
data: formdata,
processData: false,
mimeType:"multipart/form-data",
success: AjaxGetFieldDataSucceeded,
error: AjaxGetFieldDataFailed
});
function AjaxGetFieldDataSucceeded(data) {
if (data != "[]") {
$("#uploaded2").dataTable({
"processing": true,
"serverSide": false,
"columns": [
{ "data": "phone_number" },
{ "data": "ccompany" },
{ "data": "ctitle" },
{ "data": "cfname" },
{ "data": "clname" },
{ "data": "caddr1" },
{ "data": "caddr2" },
{ "data": "caddr3" },
{ "data": "cemail" },
]
});
}
}
This discussion has been closed.
Answers
Within
$("#uploaded2").dataTable({
you can trydata: data
to set the data object.Kevin