"ajax": {
"url": url,
"type": "GET",
"datatype": "json",
"data": { id: id}
//,
//"success": function (data) {
// if (!data.data)
// ShowErrorMessage(data.message);
//}
},
"columns": [
{ "data": "ID" },
{ "data": "Name" },
{ "data": "Time" }
],
"columnDefs": [{
"targets": 2,
"data": "Time",
"render": function (data) {
return (ToJavaScriptDate(data));
}
}]
});
Above the sample code, which will populate a datatable using ajax GET call. The issue here is, sometimes I will return a valid error message instead of table data from ajax response.
So when ever there is data in data.data, I need to populate the table and if data is not there, I need to populate the data.message as custom error message. Here both the calls are success calls but whether to display the table content or error message depends.
I tried "success" attribute but I am not sure how to manually bind the columns when there is data in data.data