如何从php中获取datatables jQuery插件的json数据 - php

我是PHP的新手,正在尝试使用Datatables jQuery插件。我知道我必须从.php文件中获取数据,然后在数据表中使用它,但是我似乎无法通过ajax将其传递给数据表。我设法从数据库中获取数据,并对其进行json编码,但是后来我不知道如何在我的index.php文件中调用它,并在其中显示它。我究竟做错了什么?
这是我的代码:

HTML(已编辑):

       <!-- DataTables CSS -->
< link rel='stylesheet' type='text/css' href='http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/css/jquery.dataTables.css'>

< !-- jQuery -->
< script type='text/javascript' charset='utf8' src='http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.2.min.js'></script>

<!-- DataTables -->
< script type='text/javascript' charset='utf8' src='http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/jquery.dataTables.min.js'></script>

< script type='text/javascript'>
  $( document ).ready(function() {
$('#tabela').dataTable({
                  'bJQueryUI' : true,
                  'sPaginationType' : 'full_numbers',
                  'bRetrieve' : true,
                  'bFilter' : true,
                  'iDisplayLength': 10,
                  'bProcessing' : true,
                  "sAjaxSource": "adminmysqli.php"

        });   
});
< /script>

来自fetchdata.php的数据:

{"iTotalRecords":"41","iTotalDisplayRecords":"41","aaData":
[["2","Arya","Stark","612345555","Braavos"],
["3","Jon","Snow","612345655","The"], 
["4","Meryn","Trant","612345679","Tirane"],  
["5","Sansa","Stone","692345678","Durres"],
["6","Myda","Slate","612345676","Tirane"],
["7","Varys","Bird","612345689","Tirane"], 
["9","Stannis","Baratheon","612345678","Tirane"],
["10","Shireen","Burn","612345678","Iron"],
["11","Selyse","Tully","612345678","Tirane"],
["12","Lyanna","Dread","612345678","Tirane"],
["13","Viserys","Targaryen","612345678","Durres"],
["14","Daennerys","Stormborn","612345678","Tirane"],
["15","Khaal","Drogo","612345678","Tirane"],
["16","Jojen","Reed","612345678","Tirane"],
["17","Theon","Greyjoy","612345678","Tirane"],
["18","Osha","Green","612345678","Tirane"],
["19","Oberyn","Martell","612345678","Tirane"],
["20","Ellaria","Sands","612345678","Tirane"],
["22","Tommen","Laster","612345678","Tirane"],
["23","Robert","Baratheon","612345678","Tirane"],
["24","Jamie","Lannister","612345678","Tirane"],
["25","Tywin","Bolt","612345678","Tirane"],
["26","Tyrion","Imp","612345678","Tirane"],
["27","Gregor","Clegane","612345678","Tirane"],
["28","Qyburn","Exper","612345678","Tirane"],
["30","Daniel","Howell","612345678","Tirane"],
["31","Samwell","Tarly","612345678","Tirane"],
["32","Aemon","Maester","61234569","Tirane"],
["33","Jaqen","Hgar","612345678","Tirane"],
["34","Daario","Naharis","612345678","Tirane"],
["35","Jorah","Bear","612345678","Tirane"],
["36","Irri","Mereen","612345678","Tirane"],
["37","Margaery","Tyrell","612345678","Tirane"],
["38","Renly","Baratheon","612345678","Tirane"],
["44","Eddard","Stark","697845123","Winterfell"],
["45","Miranda","Hart","692314256","Durres"],
["46","Stray","Cat","691234567","Here"],
["48","Haley","Dunphy","653746111","Tirana"],
["51","Asli","Felin","666111222","South"],
["55","Alison","Brie","667755333","Saye"],
["58","Marie","Curie","665544333","Radium"]]}

编辑:
感谢您的答复,我设法删除了mData属性来获取格式化的数据,而且我错误地加载了脚本,从而阻止了我获取数据。

参考方案

将您的sAjaxSource路径更改为您的php文件,然后使用以下代码重试:

<script type='text/javascript'>
$( document ).ready(function() {
    $('#tabela').dataTable({
        'bJQueryUI' : true,
        'sPaginationType' : 'full_numbers',
        'bRetrieve' : true,
        'bFilter' : true,
        'iDisplayLength': 10,
        'bProcessing' : true,
        "sAjaxSource": "fetchdata.php"
    });
});
</script>

45码