so.. i have an ajax read from database using an api controller (GET method)
the data that is coming back from the ajax is correct but i cant seem to populate it into datatables
$(document).ready(function () {
$.ajax({
dataType: "json",
url: webRoot + "/api/report",
contentType: "application/json",
type: "GET",
//data: JSON.stringify(),
success: function (tData) {
loadData(tData);
},
error: function (err) {
console.log(err);
},
});
});
function loadData(tData) {
$("#example").DataTable({
data: tData
});
}
this is my latest try:
$(document).ready(function () {
$("#example").DataTable({
ajax: {
url: "/api/report",
type: "GET"
}
});
});
and this is the error i get in console:
2
Answers
thank you everyone issue solved just needed to push the data from the ajax pull to an array of objects than to the data table.
Consider the following example.
You will want to test your
url
manually in browser to ensure that you’re getting expected results.Update
Consider the following code based on what you’re using.