How can I save ajax response in variable?

How can I save ajax response in variable?

WhaleWhale Posts: 1Questions: 1Answers: 0
edited September 2015 in Free community support

How can I save ajax response in variable data?
success function breaks the table

        var table = $('#example_table'), data;
        table.dataTable({
            ajax: {
                url: '/admin.php',
                data: {
                    modules: 'items',
                    action: 'get'
                },
                type: 'POST',
                success: function (res) {
                    data = res
                }
            },
            columns: [{
                data: 'id'
            }, {
                data: 'label'
            }, {
                data: 'description'
            }, {
                data: function (row) {
                    return '<button type="button" onclick="admin.item.change(' + row['id'] + ')" class="btn btn-primary">Open</button>'
                }
            }],
            info: false,
            lengthChange: false,
            pageLength: 20
        })

This question has an accepted answers - jump to answer

Answers

  • ThomDThomD Posts: 334Questions: 11Answers: 43
    Answer ✓

    As far as I know, the ajax parameter of the DT configuration is not a complete ajax call. it is a hint to DT on how to deal with ajax sourced data. For a complete handling of an Ajax data source, I use JQuery's $.ajax and then invoke DT through the success parameter of that.

This discussion has been closed.