对不起,我对Django非常陌生,我试图使用从服务器返回的一些数据来laod一个jQuery数据。json回来的格式很好。但是,数据没有加载到表中,我在firebug控制台中得到了以下错误:
TypeError: aData is undefined
for ( i=0 ; i<aData.length ; i++ ) {此外,我尝试使用sAjaxDataProp选项来调整aaData的默认行为,但我不知道应该将其设置为什么。无论如何,下面是每件事的代码。
jquery:
$(document).ready(function () {
$('#rfctable').dataTable({
"sAjaxDataProp": '', // I don't know if I need this or how to deal with it
"ajax": 'http://127.0.0.1:8000/api/',
"columns": [
{ "fields": "rfc_number"},
{ "fields": "rfc_title"},
{ "fields": "rfc_question"},
]
});
});html:
<table id="rfctable" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>Rfc Number</th>
<th>RFC title</th>
<th>RFC Questions</th>
</tr>
</thead>
</table>json从网址回来:
[
{
"pk": 1,
"model": "rfc.rfcdocument",
"fields": {
"rfc_title": "123123123123",
"rfc_answer_reviewed_by": 1,
"rfc_required_fcd": true,
"rfc_drawing_detail_number": "123",
"rfc_required_sketch": true,
"rfc_answer_authorized_by": 1,
"rfc_issued_by": 1,
"rfc_answer_issued_date": null,
"rfc_specification_section": "34-5",
"rfc_answered_date_architect": null,
"rfc_question": "Salam baba?",
"rfc_issued_date": null,
"rfc_answer": "salama back!",
"rfc_project": 1,
"rfc_required_fls_review": true,
"rfc_drawing_page_number": "54",
"rfc_issued_to": 1
}
}
]如果有人能帮忙我会很感激的。
发布于 2014-06-03 23:18:28
库正在寻找来自服务器的响应的aaData属性中的数据。因为服务器正在返回一个对象列表,所以当它试图访问它时,它表示它是未定义的。
sAjaxDataProp不能使用空字符串。您可以阅读更多关于您应该从这里的服务器返回的内容:http://legacy.datatables.net/usage/server-side。
将jQuery部件更改为:
$(document).ready(function () {
$('#rfctable').dataTable({
"sAjaxDataProp": 'data',
"ajax": 'http://127.0.0.1:8000/api/',
"columns": [
{ "fields": "rfc_number"},
{ "fields": "rfc_title"},
{ "fields": "rfc_question"},
]
});
});将服务器的响应更改为:
{"data": [
{
"pk": 1,
"model": "rfc.rfcdocument",
"fields": {
"rfc_title": "123123123123",
"rfc_answer_reviewed_by": 1,
"rfc_required_fcd": true,
"rfc_drawing_detail_number": "123",
"rfc_required_sketch": true,
"rfc_answer_authorized_by": 1,
"rfc_issued_by": 1,
"rfc_answer_issued_date": null,
"rfc_specification_section": "34-5",
"rfc_answered_date_architect": null,
"rfc_question": "Salam baba?",
"rfc_issued_date": null,
"rfc_answer": "salama back!",
"rfc_project": 1,
"rfc_required_fls_review": true,
"rfc_drawing_page_number": "54",
"rfc_issued_to": 1
}
}
]}您还应该在响应中返回iTotalRecords、iTotalDisplayRecords和sEcho。
https://stackoverflow.com/questions/24021602
复制相似问题