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

标签 javascript jquery ajax json datatables

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

I am making ajax request to server, its returning the above json data.But i >am getting the json parse error

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

最佳答案

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

代码:

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

关于javascript - 使用 jquery 数据表时出现 JSON 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28473055/

相关文章:

javascript - 在 C# 函数之前等待弹出响应

javascript - Socket.io-客户端连接到多个服务器

jquery - @mentions 和 #tags 的文本区域自动建议

javascript - 如何克服 CodeIgniter 的不良做法

php - 在 json 代码igniter 中从 Controller 检索数据

javascript - 如何 react 性地渲染你自己的对象实例? (不是游标对象)

javascript - 如何在 python selenium 的 css 选择器中选择下一个直接元素?

javascript - 初始加载时数据表卡在 "Processing"

javascript - 如何加载页面而不重新加载它?

jquery - 使用 javascript .submit() 的 AJAX Rails 复选框