I try to implement jquery datatable ajax-source usage in Django however have some problems. The ajax call is working great and get the response however after that aData is undefined error is raised in javascript.
What would be the problem ?
These are what I have so far.
views.py
def model_history(request):
o = Model.objects.get(id=request.GET["pk"])
items_list = list(o.lastupdate_set.all().values())
return HttpResponse(simplejson.dumps(items_list),'application/json')
js
function viewModelHistory(pk){
url1 = "/model/history/?pk="+pk;
$('#history').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": url1,
"fnServerData": function ( sSource, aoData, fnCallback ) {
$.ajax( {
"dataType": 'json',
"type": "POST",
"url": sSource,
"data": aoData,
"success": fnCallback
} );
}
} );
}
listmodel.html
<table id="history">
<thead>
<tr>
<th>col1</th>
<th>col2</th>
<th>col3</th>
<th>col4</th>
<th>col5</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
本文讨论了在Django应用中使用jQuery DataTables进行AJAX源数据加载时遇到的aData is undefined错误,并提供了解决方法。通过调整JSON响应格式和回调函数参数,可以确保数据正确呈现。

1461







fnCallbackdo and what parameters does it expect? – ilvar Apr 30 '12 at 4:31