Datatables jquery datatable未使用给定的响应进行初始化

Datatables jquery datatable未使用给定的响应进行初始化,datatables,Datatables,我想用生成的响应初始化数据表 我的回答是这样的 {data: Array(3), status: true} data : Array(3) 0 : {countryId: 1, countryName: "sampleCountry", countryShortCode: "sampleCode", status: "yes"} 1 : {countryId: 2, countryName: "pakistan", countryShortCode: "pak", statu

我想用生成的响应初始化数据表

我的回答是这样的

{data: Array(3), status: true}
data :  Array(3)
0  :    {countryId: 1, countryName: "sampleCountry", countryShortCode: "sampleCode", status: "yes"}
1  :    {countryId: 2, countryName: "pakistan", countryShortCode: "pak", status: "yes"}
2  :    {countryId: 3, countryName: "sample2", countryShortCode: "pak", status: "yes"}
请看我的html

<table class="table table-striped" id="countryTable">

                                    <thead>
                                      <tr>
                                        <th>S.NO.</th>
                                        <th>Country Name</th>
                                        <th>Country Short Name</th>


                                      </tr>
                                    </thead>
                                    <tbody>
                                   </tbody>
</table>
初始化后,数据表显示为表中无可用数据,但该表使用datatable插件初始化。 数据未进入表中。
我的代码出了什么问题,请帮助我。

代码看起来不错,您只需将
mydata
更改为
data
,如下所示:

var响应={
数据:[{
国号:1,,
countryName:“sampleCountry”,
countryShortCode:“sampleCode”,
状态:“是”
},
{
国号:2,,
国名:“巴基斯坦”,
countryShortCode:“巴基斯坦”,
状态:“是”
},
{
国号:3,,
国家名称:“样本2”,
countryShortCode:“巴基斯坦”,
状态:“是”
}
],
状态:正确
}
$(“#countryTable”).DataTable({
“fnRowCallback”:函数(nRow、aData、iDisplayIndex){
$(“td:first”,nRow).html(iDisplayIndex+1);
返回nRow;
},
摧毁:没错,
数据:response.data,
栏目:[{
数据:“countryId”
},
{
数据:“countryName”
},
{
数据:“countryShortCode”
}
]
});

没有。
国名
国家简称
$.ajax({        
            url : url,

            type:"get",     
            contentType:'application/json; charset=utf-8',  
            dataType: 'json' ,
            async: false,  
            success:function(response) 
            {     
                alert(response.data);  

                  $('#countryTable').DataTable( {
                        "fnRowCallback" : function(nRow, aData, iDisplayIndex){
                            $("td:first", nRow).html(iDisplayIndex +1);
                           return nRow;
                        },
                         destroy: true,
                        mydata: response.data, 
                        columns: [     
                             { mydata:'countryId'},   
                             { mydata:'countryName'},
                             { mydata:'countryShortCode'}     


                        ]  
                    } );         

                console.log(response);
            }
        });