AJax.Reload returning invalid Json when the Json is valid.
AJax.Reload returning invalid Json when the Json is valid.
When my datatable is first created i call a function GetJsonData()
var jsonData = GetJsonData();
When i initiate the datatable my data field looks like this.
"data": JSON.parse(jsonData).data
GetJsonData makes an ajax call and returns my json array. This works fine.
When i want to reload the table i have another function called reloadTable
function reloadTable() {
var table = $('#tblCases').DataTable();
var jsonData = JSON.parse(GetJsonData()).data;
table.ajax.reload(jsonData);
}
you can see this function calls the same function GetJsonData which works on the initial load.
I checked the json that is being returned and json lint says its valid. I can post the json object if needed.
Is there something else i am doing wrong?
Here is an example. It isn't throwing the same errors, but its also not working. If you click on the button to reload the table it throws errors in the console.
http://live.datatables.net/zibohaji/5/edit?html,css,js,output
This question has an accepted answers - jump to answer
Answers
I figured out what i was doing wrong.
This article helped me out a lot.
https://medium.com/code-kings/datatables-js-how-to-update-your-data-object-for-ajax-json-data-retrieval-c1ac832d7aa5#.v6xjn9rzs
I would suggest to use these tool to helps validate and analyse JSON data such as http://codebeautify.org/jsonviewer and http://jsonformatter.org