我用一个AJAX调用从我的服务器获取JSON信息加载表:无法获取数据表与数据从JSON
console.log('GOT IT');
/* attach a submit handler to the form */
$('#search-form').submit(function(event) {
/* stop form from submitting normally */
event.preventDefault();
/* get the action attribute from the <form action=''> element */
var form = $(this),
url = form.attr('action');
var data = $('form#search-form').serialize()
/* Send the data using post with element id name and name2*/
var posting = $.post(url, data, datype = 'json');
/* Alerts the results */
posting.done(function(data) {
$('#results-table').dataTable({
ajax: data
});
});
});
数据本身是从我的服务器在这种格式的JSON字符串返回:
{
"success":true,
"result":[{"salutationtype":"Ms.","firstname":"Jennifer","contact_no":"CON1","phone":"","lastname":"Gale"
}
我想我可能不得不改变dataSrc
到“结果”,但没有奏效。我还试图用$.jsonParse()
和JSON.parse()
解析JSON,并将其作为对象而不是JSON字符串提供给dataTables
,但都无效。
你在'data' var中得到了回应? –
尝试用data.result更改数据 – gaetanoM
试试这个。 '$( '#结果表')的dataTable({ aaData:数据 });' –