So I can easily pass data to my table when the JSON data is read from a .txt file.
However, when I use ajax to hit an endpoint and return data, I get errors. Can anybody see what's wrong?
var table;
$.ajax({
url: '../forms/test/get_data',
type: 'GET',
dataType: 'json'
})
.done(function() {
console.log("success");
})
.fail(function() {
console.log("error");
})
.always(function(data) {
console.log(data); // This comes back correctly and in the same format as the txt file.
table = $('#feeds').DataTable( {
//"ajax": "/javascripts/test/ajax/data/object.txt",
"ajax" : function(dataa, callback, settings) {
callback(data)
},
"scrollX" : true,
"data" : data,
"columns": [
{
"className": 'details-control',
"orderable": false,
"data": null,
"defaultContent": ''
},
{ "data": "id" },
{ "data": "status" }
]});
});
I get "Uncaught TypeError: Cannot read property 'row' of undefined at n.fn.init.createdRow (eval at (jquery-1.12.0.min.js:2), :63:45)" as an error in my console.
User to JSON.parse() method for convert string data to object data like
: "data" : JSON.parse(data),
try above Code..
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.