使用jquery数据表时出现JSON错误

时间:2015-02-12 08:53:08

标签: javascript jquery ajax json jquery-datatables

[{"name":"aaa","firstname":"bbb","lastname":"ccc"},
{"name":"qqq","firstname":"eee","lastname":"mmm"},
{"name":"www","firstname":"ooo","lastname":"lll"}]
  

我正在向服务器发出ajax请求,它返回上面的json数据。但是我正在获取json解析错误

$(document).ready(function() {
    $('#example').dataTable( {
        "processing": true,
        "serverSide": true,
        "ajax": {
                "url": "http://example",
                "dataType": "jsonp",
        "columns": [
                { "data": "name"},
                { "data": "firstname" },
                { "data": "lastname" }
            ]
            }
        } );
});

1 个答案:

答案 0 :(得分:1)

您的ajax属性不应包含列属性。:

代码:

$(document).ready(function() {
    $('#example').dataTable( {
        "processing": true,
        "serverSide": true,
        "ajax": {
                "url": "http://example",
                "dataType": "jsonp"
        },
        "columns": [
                 { "data": "name"},
                 { "data": "firstname" },
                 { "data": "lastname" }
            ]
        } );
});