这是我第一次尝试datatables
。我想调用ajax
函数从数据库返回数据(MariaDB
),并填充php
文件中现有table
的rows
和cells
。没有数据从ajax调用返回给jquery数据表
有关数据域代码的简化版本是这样的:
$('#tbl_resultados').dataTable({
"bProcessing": true,
"sAjaxSource": "/apls/indicadores/indic_acess.php",
"sAjaxDataProp": "data",
"fnServerData": function (sSource, aoData, fnCallback) {
request = $.ajax({
"dataType": 'json',
"type": "GET",
"url": sSource,
"data":{
"fn": "lines",
"indic_per": indic_per,
},
"success": fnCallback
});
},
"aoColumns": [
{ "mDataProp": "id"},
{ "mDataProp": "per"},
],
});
我已经试过与不"bServerSide": true,
,但不能获取要显示在table
数据。 Firebug
返回TypeError: aData is undefined
。
以下正在说的the example我在php
中构建了一个函数,它返回一个json
的结构。
function getLines()
{
echo "{ \"aData\":[
[
\"25983\",
\"2010\"
],
[
\"90420\",
\"2011\"
]
]
}";
}
就像我说的,我已经与datatables
没有经验不知道是否使用aData
或aaData
,还是什么尝试更多。
有一些我必须错过...我用你的例子。在'getLines'中''Php'函数做了一个'回应'你的回答';'并且逃脱了引号。在firebug中,作为对'http'' GET'方法的响应,有:'{“aaData”:[“Trident”,“Internet Explorer 4.0”,“Win 95 +”,“4”], [ “Trident”,“Internet Explorer 5.0”,“Win 95 +”,“5”], [“Trident”,“Internet Explorer 5.5”,“Win 95 +”,“5.5”], [“Trident” Internet Explorer 6“,”Win 98 +“,”6“], [”Trident“,”Internet Explorer 7“,”Win XP SP2 +“,”7“] ]。但仍然得到'TypeError:aData是未定义的'错误。 – Luis
您是否尝试从示例(通过复制源代码)开始,并试图替换您需要的内容? – PoulsQ
这个例子不像我打算做的那样:''sAjaxSource“:'../ examples_support/json_source.txt',而不是使用'ajax'调用一个php函数。 – Luis