so i am getting the common error "DataTables warning: table id=myTable - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1". the solution I have tried online is not really working out for me. so basically I am testing a local JSON file and using data table ajax method to populate the table. i cant seem to figure out what i did wrong.
$(document).ready(function () {
var request = new XMLHttpRequest();
request.open("GET", "./test.json", false);
request.send(null)
var responseMain = JSON.parse(request.responseText);
var my_array = responseMain.feed.entry;
$("#totalnum").html(my_array.length);
var obj_stage = [];
$.each(my_array, function (index, value) {
obj_stage.push(value.content.F_Form1);
console.log("inside each", obj_stage)
});
console.log("out side each", obj_stage)
console.log("what type",typeof obj_stage);
$('#myTable').DataTable({
"ajax": obj_stage,
"columns": [
{ "data": obj_stage["-flowState"] },
{ "data": obj_stage["-flowState"] },
]
});
});
//console.log("value",value.content.F_Form1["-flowState"])
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.18/css/jquery.dataTables.min.css">
<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"></script>
<script src="https://cdn.datatables.net/1.10.18/js/jquery.dataTables.min.js"></script>
<script src="./test.js"></script>
</head>
<body>
<h1 id="totalnum"></h1>
<table id="myTable" class="display" style="width:100%">
<thead>
<tr>
<th>Stage Name</th>
<th>Asap ?</th>
</tr>
</thead>
</table>
</body>
</html>
data: obj_stageinstead of ajax.