2

I'm trying to setup datables with sorced data from ajax. The file outputs an array with objects:

[{"column":"content","column":"content"}]

But it's not loading the data, it keeps proccessing.

$('#example').DataTable( {
    processing: true,
    lengthChange: false,
    ajax: '/get?op=2',
    language: {
        "url": "//website.com/js/DataTables-Spanish.json"
    },
    columns: [
        { data: 'id' },
        { data: 'columns' }
        // more columns
    ],
    select: true
});

This is the code of the file:

if ($op === 2) {

    $result = $functions->get_prop_table_test();

    header('Content-type: text/json');
    header('Content-type: application/json');
    echo json_encode($result);
}

The only error I see is in the console:

TypeError: f is undefined    datatables.min.js:60:375
ia/<()                       datatables.min.js:60
ra/i()                       datatables.min.js:47
ra/o.success()               datatables.min.js:47
n.Callbacks/j()              jquery.min.js:8
n.Callbacks/k.fireWith()     jquery.min.js:8
x()                          jquery.min.js:10
.send/b/<()                  jquery.min.js:10

https://cdn.datatables.net/s/zf/dt-1.10.10,b-1.1.0,se-1.1.0/datatables.min.js

Where is the problem?

2 Answers 2

2

You need to use dataSrc: '' as shown below to match your JSON data format, see dataSrc for more information. Use the following initialization options:

ajax: {
   url: '/get?op=2',
   dataSrc: ''
}
Sign up to request clarification or add additional context in comments.

Comments

0

Typically an error like this originates in the data returned. If you're using Spanish language data, it might be the encodings don't match (UTF-8 vs ASCII, etc) and the accents are causing you trouble.

Can you post a sample of the data you're returning from $functions -> get_prop_table_test();

1 Comment

I removed the language option, still not working. The data returned is exactly as the example i put above, an array with an object per row.

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.