I am not able to retrieve data in datatable using datatable.js. The Json response is a string but in the output I get every character of the string in each row rather that jst two entries.
Please help. Thanks in advance
function fillGrid() {
$.ajax({
type: 'POST',
url: 'BehindCode/client.aspx/fillgrid',
cache: false,
dataType: "json",
contentType: "application/json; charset=utf-8",
beforeSend: function () {
$('#gridLoadingDiv').attr('style', 'display:block');
},
complete: function () {
$('#gridLoadingDiv').attr('style', 'display:none');
},
data: "{}",
success: function (data) {
data = data.d;
alert(data);
$("#clientTable").DataTable({
"searching": true,
"processing": true,
"data": data,
"columns": [{
"title": "CLIENT NAME"
}]
});
}
});
}
C# code..from where data is being retreived..
[WebMethod]
public static string fillgrid()
{
BehindCode_client client = new BehindCode_client();
string strfetch = "SELECT CLIENT_NAME FROM k_client_master";
string aadata = "";
client.ds = client.DEngine.GetDataSet(strfetch, "Data", client.conn);
if (client.ds != null && client.ds.Tables[0].Rows.Count > 0)
{
aadata = JsonConvert.SerializeObject(client.ds);
// aadata = "{'draw':1, 'recordsTotal':2, 'recordsFiltered':2, 'data':[{'CLIENT_NAME': 'Pyrotech'},{'CLIENT_NAME':'Workspace'}]}"; // tried this also
// aadata = "{'data':[{'CLIENT_NAME': 'Pyrotech'}, {'CLIENT_NAME':'Workspace'}]}"; // tried this as well
}
return (aadata.Replace("'","\""));
}
}
JSON Response as in developer tools

Output in datatable

enteries in database which are retreived
