使用jquery数据表时出现JSON错误 [英] JSON error on using jquery datatable

查看:127
本文介绍了使用jquery数据表时出现JSON错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我正在向服务器发出ajax请求,它返回了上面的json数据.但是我> am遇到了json解析错误

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属性不应包含column属性.

Your ajax attribute should not contain the column attribute.:

代码:

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

这篇关于使用jquery数据表时出现JSON错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆