aData is undefined

 

 

 

{"aaData": [["blah1", "blah2", "blah3"]]}

 

 

详情看;:

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>
share improve this question
 
   
What does fnCallback do and what parameters does it expect? –  ilvar Apr 30 '12 at 4:31

2 Answers

It looks like you have an issue with the format of your JSON structure. jquery.datatables expects it to look something like

{"aaData": [["blah1", "blah2", "blah3"]]}

If your JSON looks like

[["blah1", "blah2", "blah3"]]

In your view.py you need to wrap your item_list in a dictionary like so:

items_list_dict = {}
items_list_dict.update({'aaData': items_list})
return HttpResponse(simplejson.dumps(items_list_dict),'application/json')
share improve this answer
 

It will be helpful to post your JSON output, but I assume it looks like this:

[["key":"val"],["key":"val"]]

if so you need to remove your keys from the json. Datatables expects json like this:

[["val"],["val"]]

One thing you can do is make a list of list from your query

my_json = []
for item_list in items_list:
    a = [item_list.xxx_column_name_xxx]
    my_json.append(a)

items_list_dict = {}
items_list_dict.update({'aaData': my_json})
data = json.dumps(items_list_dict)

return HttpResponse(data, mimetype='application/json')
share improve this answer
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
威刚2256k是一种类型的存储卡,它可用于存储和传输数据。以下是威刚2256k开卡的教程: 1. 准备工作:首先,确保您已经购买了一张威刚2256k存储卡,并准备好将其插入您的设备中。另外,您可能需要一个读卡器,用于将卡连接到计算机或其他设备。 2. 插入存储卡:找到您设备的存储卡槽,通常它位于手机或相机的侧面或底部。小心地将威刚2256k存储卡插入卡槽中,确保卡片正确对齐并轻轻推入直到卡片完全插入。 3. 连接存储卡(如果需要):如果您使用的是读卡器而不是直接将存储卡插入设备,请将读卡器插入计算机的USB接口或其他兼容接口。根据提示插入存储卡,等待设备识别存储卡。 4. 格式化存储卡(可选):如果您使用的是威刚2256k卡的全新卡片,您可能需要在首次使用前进行格式化。在计算机上打开文件资源管理器(Windows)或Finder(Mac)等文件管理工具,找到存储卡的驱动器,并右键单击选择“格式化”。按照提示进行操作,并等待格式化过程完成。 5. 开始使用:一旦您的设备或计算机识别到存储卡,您就可以开始使用威刚2256k卡了。您可以将文件、照片、视频等保存到存储卡中,或者从存储卡中复制和传输数据。 需要注意的是,在使用威刚2256k卡时,请确保遵循设备或计算机的安全卸载步骤,以防止数据丢失或损坏。此外,避免在卡片仍然连接或正在读写数据时将其突然拔出,以免导致卡片故障。 希望以上教程对您有帮助!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值