How to pass json data which is sourced from ajax post request via a service into jQuery DataTable

How to pass json data which is sourced from ajax post request via a service into jQuery DataTable

HammadRHammadR Posts: 2Questions: 1Answers: 0

I have an asp.net webforms appication in it I have an HTML table which is getting populated via ajax call sourced by a service, I want to convert the table into jQuery DataTable and source the data to the datatable but couldn't get it done and over click it is throwing 2 errors in alert (1) is "DataTables warning: table id=tblnotificationlogHistory - Ajax error. For more information about this error, please see http://datatables.net/tn/7" and (2) is "DataTables warning: table id=tblnotificationlogHistory - Cannot reinitialise DataTable. For more information about this error, please see http://datatables.net/tn/3".
Code:
``` jQuery(".statusname, .commentsHistory").click(function (event) {
debugger;
var callForCommHistory = (jQuery(this).attr("class") == 'commentsHistory');
var ccrsflattenId = jQuery(this).next('._ccrsflattenId').text();
var FlattenExtID = jQuery(this).next('._ccrsflattenId').next('._FlattenExtID').text();
var webMethod = '/Service/CRService.asmx/GetUnmatchedHistoryStatuses'
var parameters = "{ccrsflattenId: " + ccrsflattenId + " , FlattenExtID: " + FlattenExtID + " , isCallForCommHistory: " + callForCommHistory + "}";
console.log('parameters: ' + parameters);
showLoader();
jQuery.noConflict();
jQuery(".tblnotificationlogHistory").DataTable({
paging: false,
searching: false,
info: false,
processing: true,
serverside: true,
"ajax": {
"type": "POST",
"url": "webMethod",
"data": "parameters",
"contentType": "application/json; charset=utf-8",
"dataType" : "json"
},
"columns": [
{ "data": "createdDate" },
{ "data": "comments" },
{ "data": "updatedby" }
]
});
});

Answers

  • kthorngrenkthorngren Posts: 21,173Questions: 26Answers: 4,923

    Did you follow the troubleshooting steps provided in the links both errors gave? That is the place to start.

    Kevin

  • HammadRHammadR Posts: 2Questions: 1Answers: 0

    Yes I did, but did not get the desired result. New with working datatable and unable to populate the data in it.

  • kthorngrenkthorngren Posts: 21,173Questions: 26Answers: 4,923

    There isn't enough information to help. What did you find with the Ajax error? Likely its a problem you need to troubleshoot on your server. The Cannot reinitialise error is do to reinitializing datatables without destroying it first. How are eyou reinitializaing datatables?

    Please post a link to your page or a running test case replicating the issues so we can take a look.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

This discussion has been closed.