Assign AJAX success JSON data to DataTables.

Assign AJAX success JSON data to DataTables.

deepak04deepak04 Posts: 1Questions: 0Answers: 0
edited May 2013 in General
How to assign jQuery AJAX success data to DataTables?

The jQuery AJAX return data like:---

[
{"CustomerName":"ABC","CustomerID":"001"},
{"CustomerName":"CDE","CustomerID":"002"},
{"CustomerName":"EFG","CustomerID":"003"},
{"CustomerName":"GHI","CustomerID":"004"},
{"CustomerName":"IJK","CustomerID":"005"}
]



My Code is

<!DOCTYPE html>


Flexmonster Demo



$(document).ready(function () {
$('#example').dataTable({
"bServerSide": true,
"sAjaxSource": "MethodName",
"sServerMethod": "POST",
"bStateSave": true,
"bPaginate": true,
"bProcessing": true,
"sPaginationType": "full_numbers",
"aaSorting": [[1, 'asc']],
"fnServerData": fnServerObjectToArray(),
});
});

fnServerObjectToArray = function (aElements) {
return function (sSource, aaData, fnCallback) {
$.support.cors = true;
$.ajax({
"type": "POST",
"url": "MethodName",
"data": JSON.stringify({'ParameterA': '123', 'ParameterB': '123'}),
"contentType": "application/json; charset=utf-8",
"dataType": "json",
"processdata": true,
"success": function (data) {
var output = data.MethodNameResult[0];
var json = JSON.stringify(output);
fnCallback(json);
},
error: function (err) {
alert(err);
}
});
}
};
This discussion has been closed.