简体   繁体   中英

JSON error on using jquery datatable

[{"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" }
            ]
            }
        } );
});

Your ajax attribute should not contain the column attribute.:

Code:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM