0

I'm trying to pass some data to DataTables as an array, initialized to a variable that I have tried to initialize as an array. I have also tried wrapping the array up as JSON per the examples on Datatables website, adding an encircling pair of braces, and setting "data" to equal the array. That JSON validates correctly with JSONLint. However, in all of these cases, Datatables gives me the dreaded:

"DataTables warning: Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1"

Here, and in the JSFiddle, is a minimal example:

    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
  • see doc: use $('#example').DataTable( { data: data } ); if you not get data by ajax Commented May 12, 2015 at 15:02

1 Answer 1

1

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

You were trying to send an ajax request to the table itself.

If you have the data already in a var then you assign it with data:

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
    });
});
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, having looked around many of the docs I was wondering why it was called 'ajax' and didn't see any examples of the use of 'data.' Not sure why this was somewhat hidden - should have RTFM instead of just looking at the website examples and google searches.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.