数据表不接受有效数组作为源(即“ajax”=)

时间:2015-05-12 14:57:55

标签: ajax json jquery-datatables

我正在尝试将一些数据作为数组传递给DataTables,初始化为我尝试初始化为数组的变量。我还尝试按照Datatables网站上的示例将数组包装为JSON,添加一对环绕的括号,并将“data”设置为等于数组。 JSON使用JSONLint正确验证。但是,在所有这些情况下,Datatables给了我可怕的:

“DataTables警告:无效的JSON响应。有关此错误的详细信息,请参阅http://datatables.net/tn/1

在这里,在JSFiddle中,是一个最小的例子:

    var dataIn = [
    ["ma\u02d0hu ha\u02d0\u00f0a", "What?", "Final 'what' interrogative in each  Yemen series is object, subject interrogatives are marked for gender", "Y24", "closed-class,interr.what,masculine,subject", "Behnstedt85YemenAtlas: m. 60", "red"], 
              ["ma\u02d0hu\u02d0\u00f0e\u0294", "What?", "Final 'what' interrogative in each  Yemen series is object, subject interrogatives are marked for gender", "Y156", "closed-class,interr.what,masculine", "Behnstedt85YemenAtlas: m. 60", "red"]
              ];

$(document).ready(function(){
    $("#results").dataTable({
        "ajax" : dataIn              
    });
});

https://jsfiddle.net/ype8zag5/2/

1 个答案:

答案 0 :(得分:1)

https://jsfiddle.net/ype8zag5/5/

您试图向表格本身发送ajax请求。

如果您已将数据存储在var中,则为其分配数据:

var dataIn = [
    [
        "maːhu haːða",
        "What?",
        "Final 'what' interrogative in each  Yemen series is object, subject interrogatives are marked for gender",
        "Y24",
        "closed-class,interr.what,masculine,subject",
        "Behnstedt85YemenAtlas: m. 60",
        "red"],
    [
        "maːhuːðeʔ",
        "What?",
        "Final 'what' interrogative in each  Yemen series is object, subject interrogatives are marked for gender",
        "Y156",
        "closed-class,interr.what,masculine",
        "Behnstedt85YemenAtlas: m. 60",
        "red"]
];

$(document).ready(function () {
    $("#results").dataTable({
        data: dataIn // Changed
    });
});