I am binding a Data table using ajax and jquery. But i am getting an error like "DataTables warning: table id=datatable - Invalid JSON response."
$(document).ready(function () {
$.ajax({
type: "post",
url: "../../loader.svc/gettabledata",
data: '{}',
contenttype: "application/json; charset=utf-8",
datatype: "json",
success: onsuccess,
failure: function (response) {
alert(response.d);
},
error: function (response) {
alert(response.d);
}
});
});
function onsuccess(responce) {
$('#datatable').DataTable(
{
"ajax":
{
"datasrc": function (responce) {
var jsonObj;
jsonObj = $.parseJSON(responce.d)
return jsonObj.d;
}
},
"columns": [
{ "data": "ID" },
{ "data": "customername" },
{ "data": "LoginName" }
]
});
}
Response text: [{"ID":1,"CustomerName":"John","LoginName":"John"}]"